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.

Dynamic field names

February 22, 2012 1:24pm

Subscribe [4]
  • #1 / Feb 22, 2012 1:24pm

    emccoe

    2 posts

    This should be simple but then again nothing ever is…..

    As field names need to be unique I am trying to concat the channel id to a field name so I can display the correct field name when using a channel tag

    Is it possible to do something like this:

    {exp:channel:entries channel="channelOne|channelTwo|channelThree" limit="3"}
    
       {extended_{channel_id}}
    
    {/exp:channel:entries}

    The code above simply displays {extended_1} {extended_2}  {extended_2} etc as a string. It’s not parsing it correctly.

    Thanks.

  • #2 / Feb 23, 2012 5:56am

    emccoe

    2 posts

    Can you specify the parse order of a channel tag? It dosen’t seem to have an effect.

  • #3 / Feb 23, 2012 6:16am

    Mark Bowen

    12637 posts

    You’ll need to do something like this :

    {exp:channel entries channel="channelOne|channelTwo|channelThree" limit="3"}
    
    {if channel_short_name == "channelOne"}
    {my_field_in_channel_one}
    {/if}
    
    {if channel_short_name == "channelTwo"}
    {my_field_in_channel_two}
    {/if}
    
    …and so on and so forth…
    
    {/exp:channel:entries}

    Documentation link for {channel_short_name} variable

    Hope that helps a bit.

    Best wishes,

    Mark

     

  • #4 / Feb 23, 2012 7:25am

    emccoe

    2 posts

    Hi Mark,

    Thanks for the response. That was the approach that I was trying to avoid but if it’s the only way then I’ll go with it. Thanks!

  • #5 / Feb 23, 2012 8:28am

    Boyink!

    5011 posts

    You’re running into parse order issues, and you can’t dictate EE’s parse order.

    You can do {{segment_2}_field_name} (if you match template group names to channel names this may work) or {{site_short_name}_field_name} in MSM installs.

  • #6 / Feb 23, 2012 3:44pm

    Shane Eckert

    7174 posts

    Hello emccoe,

    The parse order is master that must be obeyed! 😊 I have had my fair share of headaches when all I had to do was look at the parse order.

    Is there anything else I can help you with?

    Cheers,

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

ExpressionEngine News!

#eecms, #events, #releases