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.

Prefixing custom fields

February 26, 2014 5:00am

Subscribe [3]
  • #1 / Feb 26, 2014 5:00am

    kenny2

    90 posts

    Can the new Template Layouts be used to prefix custom fields?

    I have 2 product channels that have virtually identical fields, but because of the way CartThrob tracks inventory I cannot share a field group over these two channels. This leads to some bloat in my templates that I would like to cut down.

    I was about to look in to the technique that uses Stash..
    http://expressionengine.stackexchange.com/questions/12261/set-custom-field-prefix-with-stash

    .. but if Template Layouts can be used it would make sense to use what is built in.

  • #2 / Feb 28, 2014 1:30pm

    Rob Allen

    3105 posts

    I haven’t seen the docs for Page layouts yet so don’t know.

    Have you looked into Preload Text Replacements for prefixes? http://ellislab.com/expressionengine/user-guide/templates/globals/preload_replacement.html

  • #3 / Mar 10, 2014 6:42am

    kenny2

    90 posts

    Hi Rob,
    this gives an idea of what I am trying to do, my problem is getting the prefix in the field=”” parameter. I don’t believe preload replace can be used for this?

    What I have..

    {exp:tag:related_entries channel="ch1|ch2|ch3|ch4"}
     {if channel_short_name == "ch1"}
      {exp:channel_images:images entry_id="{entry_id}" field="ch1_gallery" cover_only="yes"}
      <a href="http://{path={channel_short_name}/{url_title}}">{title}</a>
      {/exp:channel_images:images}
     {/if}
     {if channel_short_name == "ch2"}
      {exp:channel_images:images entry_id="{entry_id}" field="ch2_gallery" cover_only="yes"}
      <a href="http://{path={channel_short_name}/{url_title}}">{title}</a>
      {/exp:channel_images:images}
     {/if}
     {if channel_short_name == "ch3"}
      {exp:channel_images:images entry_id="{entry_id}" field="ch3_gallery" cover_only="yes"}
      <a href="http://{path={channel_short_name}/{url_title}}">{title}</a>
      {/exp:channel_images:images}
     {/if}
     {if channel_short_name == "ch4"}
      {exp:channel_images:images entry_id="{entry_id}" field="ch4_gallery" cover_only="yes"}
      <a href="http://{path={channel_short_name}/{url_title}}">{title}</a>
      {/exp:channel_images:images}
     {/if}
    {/exp:tag:related_entries}

    What would be better..

    {exp:tag:related_entries channel="ch1|ch2|ch3|ch4"}
      {exp:channel_images:images entry_id="{entry_id}" field="{channel_short_name}_gallery" cover_only="yes"}
      <a href="http://{path={channel_short_name}/{url_title}}">{title}</a>
      {/exp:channel_images:images}
    {/exp:tag:related_entries}

     

  • #4 / Mar 10, 2014 8:53am

    ahmad saad

    364 posts

    Hi,

    try to use parse=“inward” in ur code:

    {exp:tag:related_entries channel="ch1|ch2|ch3|ch4" parse="inward"}
      {exp:channel_images:images entry_id="{entry_id}" field="{channel_short_name}_gallery" cover_only="yes"}
      <a href="http://{path={channel_short_name}/{url_title}}">{title}</a>
      {/exp:channel_images:images}
    {/exp:tag:related_entries}

    if this don’t work u can always use embed template.

    Regard’s.

  • #5 / Mar 10, 2014 10:15am

    kenny2

    90 posts

    Great, Parse Inwards works for that scenario, but further down in my code I also have:

    {exp:tag:related_entries channel="ch1|ch2|ch3|ch4"}
    ..
    {if channel_short_name == "ch1"}
        {ch1_stub}
    {/if}
    {if channel_short_name == "ch2"}
        {ch2_stub}
    {/if}
    {if channel_short_name == "ch3"}
        {ch3_stub}
    {/if}
    {if channel_short_name == "ch4"}
      {ch4_stub}
    {/if}
    {/exp:tag:related_entries}

    I am pretty sure {{channel_short_name}_stub} will not work

  • #6 / Mar 10, 2014 10:47am

    ahmad saad

    364 posts

    Hi,

    the general way is to use your code or use embed template to avoid {if} statement.

    anyway from some time I find this addons http://devot-ee.com/add-ons/entry-data

    and I add get custom field future to it.

    I upload my version in this post , when u use this plugin u can write ur code as following:

    {exp:tag:related_entries channel="ch1|ch2|ch3|ch4" parse="inward"}
       {exp:entry_data:custom_field url_title="{url_title}" field_name="{{channel_short_name}_stub}" channel="{channel_short_name}"}
    {/exp:tag:related_entries}
  • #7 / Apr 03, 2014 11:44am

    kenny2

    90 posts

    Thanks Ahmad, I have tried your plugin but using your example I am still getting a problem passing the field name:

    {exp:tag:related_entries channel="ch1|ch2|ch3|ch4" parse="inward"}
       {exp:entry_data:custom_field url_title="{url_title}" field_name="{{channel_short_name}_stub}" channel="{channel_short_name}"}
    {/exp:tag:related_entries}

    Gives me this in the debugger:

    {exp:entry_data:custom_field url_title="my-title" field_name="{ch1_stub}" channel="ch1"}
  • #8 / Apr 03, 2014 1:25pm

    ahmad saad

    364 posts

    Hi Kenny2,

    yes this is my fault just remove the parentheses.

    {exp:tag:related_entries channel="ch1|ch2|ch3|ch4" parse="inward"}
       {exp:entry_data:custom_field url_title="{url_title}" field_name="{channel_short_name}_stub" channel="{channel_short_name}"}
    {/exp:tag:related_entries}

    Regard’s.

  • #9 / Apr 04, 2014 7:06am

    kenny2

    90 posts

    Awesome, that works really well and also inside relationships, but I am struggling to apply it to a Grid field and a CE Image field. Is this stretching what the plugin can do? (The XX is where I want the prefixed channel short name to be).

    {exp:channel:entries channel="ch1" entry_id="10"}
     {relationship_field}
      <div>
       {relationship_field:XX_main_image limit="1"}
        {exp:ce_img:single src="{relationship_field:XX_main_image:key_image}" title="{relationship_field:XX_main_image:description}"}
       {/relationship_field:XX_main_image}
       {exp:entry_data:custom_field url_title="{relationship_field:url_title}" field_name="{relationship_field:channel_short_name}_stub" channel="{relationship_field:channel_short_name}"}
      </div>
     {/relationship_field}
    {/exp:channel:entries}
  • #10 / Apr 04, 2014 8:36am

    ahmad saad

    364 posts

    Hi ,

    I don’t think this can be done , this plugin is return a single value fields.

    maybe you use embed variable here.

    Regard’s.

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

ExpressionEngine News!

#eecms, #events, #releases