ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Using custom_profile_data in conditionals.

March 12, 2012 10:55pm

Subscribe [3]
  • #1 / Mar 12, 2012 10:55pm

    Philip Cottrell

    12 posts

    I am trying to filter posts by category, based on a custom field (program_code) in the user profile.

    In order to do this I have tried various ways to form a conditional statement.

    for ex:

    {exp:member:custom_profile_data}
    {if program_code == "ENG2012"}
    {exp:channel:entries channel="{my_channel}" disable="pagination" dynamic="yes" category="11" limit="10"}
    {if:elseif program_code == "SCO2012"}
    {exp:channel:entries channel="{my_channel}" disable="pagination" dynamic="yes" category="128" limit="10"}
    {if:elseif program_code == "ITA2012"}
    {exp:channel:entries channel="{my_channel}" disable="pagination" dynamic="yes" category="126" limit="10"}
    {/if}
    {/exp:member:custom_profile_data}
    <h3>{title}</h3>
    <p>  {partner_body}<br />
       <ul>{partner_files}<br />
         <li>{file_desc}<br />
         <a href="http://{file}target=_blank" rel="noopener">{file_name}</a></li><br />
       {/partner_files}</ul><br />
      {/exp:channel:entries}

    I have discovered that the first if statement works - ie if the user is ENG2012 then they get the correct page content.  However, none of the if:elseif statements work…

    I have looked in the manual for example that may be useful but at this point I am stumped.  Anyone know if I need to formulate the code differently?  Do I need the exp:member:custom_profile_data tags to wrap around every instance of the custom field?

    THanks in advance for any assistance..

  • #2 / Mar 13, 2012 2:49pm

    Kyle Cotter

    730 posts

    Hey Philip,

    Looking at your scenario, here is how I might go about handling this.

    Since this code is being applied to all 3 channel entries loop, I would take

    <h3>{title}</h3>
    <p>{partner_body}<br />
     <ul><br />
      {partner_files}<br />
      <li>{file_desc}<br />
       <a href="http://{file}target=_blank" rel="noopener">{file_name}</a><br />
      </li><br />
      {/partner_files}<br />
     </ul>

    and turn that into a snippet.

    Then, instead of trying to add conditionals to the opening channel entries tag, apply the conditional to the entire channel entries loop like so

    {exp:member:custom_profile_data}
     
     {if program_code == "ENG2012"}
      {exp:channel:entries channel="{my_channel}" disable="pagination" dynamic="yes" category="11" limit="10"}
       {snippet_name}
      {/exp:channel:entries}
      
     {if:elseif program_code == "SCO2012"}
      {exp:channel:entries channel="{my_channel}" disable="pagination" dynamic="yes" category="128" limit="10"}
       {snippet_name}
      {/exp:channel:entries}
     
     {if:elseif program_code == "ITA2012"}
      {exp:channel:entries channel="{my_channel}" disable="pagination" dynamic="yes" category="126" limit="10"}
       {snippet_name}
      {/exp:channel:entries}
     {/if}
    
    {/exp:member:custom_profile_data}

    Based off the testing I did off of this code, this should be able to accomplish what you are trying to do.

    Let me know how it goes.

    Thanks.

  • #3 / Mar 13, 2012 3:47pm

    Philip Cottrell

    12 posts

    That works great Kyle - thanks…

    I am curious as to why the custom_member_data is so different from other fields in EE. 

    Anyway - the snippet idea certainly reduces the amount of code on the page, and keeping the whole entries tag whole seems to be what the conditional statements like.

    THanks again for your help..

    Philip

  • #4 / Mar 14, 2012 4:35pm

    Shane Eckert

    7174 posts

    Hello Philip,

    I am glad to see that Kyle was able to help! That’s awesome!

    Have a great week!

    Cheers,

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases