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.

Run-time variables

August 05, 2010 3:47pm

Subscribe [2]
  • #1 / Aug 05, 2010 3:47pm

    briansnyder

    5 posts

    Hi all -

    I’m looking to have a page template pull from one of two possible channels, depending upon the {segment_3} variable.  If the {segment_3} is equal to “associate”, I’d like to pull from a channel called “People”.  If it’s not, I’d like it to pull from a channel called “StaticContent”.

    Currently I’m using this code:

    {preload_replace:cur_channel="{if segment_3 == 'associate'}People{if:else}StaticContent{/if}"}
    {preload_replace:cur_page="{if segment_3 == 'associate'}{segment_4}{if:else}directory{/if}"}
    {exp:channel:entries channel="{cur_channel}" url_title="{cur_page}"}

    If I hard code the preload_replace values everything works well, so I’m thinking that my approach to dynamically setting the value is faulty.  Is this approach viable using EE markup, or do I need to introduce PHP in to the mix to pull it off?

    Thanks in advance for your help.
    -brian

  • #2 / Aug 05, 2010 3:58pm

    Ingmar

    29245 posts

    No, that’s not going to work; preload_replace is a simple text replacement called once, at the beginning of parsing. Try something like this:

    {if segment_3 == "associate"}
       {exp:channel:entries channel="People" url_title="{segment_4}"} 
          {title} ...
       {/exp:channel:entries}
    {if:else}
       {exp:channel:entries channel="StaticContent" url_title="directory"} 
          {title} ...
       {/exp:channel:entries}
    {/if}
  • #3 / Aug 05, 2010 4:03pm

    briansnyder

    5 posts

    Ok. The inner bit of the template is fairly large so I’d hoped to not have to duplicate.  But I can make that work.

    Thanks for your quick reply!
    -brian

  • #4 / Aug 05, 2010 4:07pm

    Ingmar

    29245 posts

    Ok. The inner bit of the template is fairly large so I’d hoped to not have to duplicate.

    Use an embedded template then, passing on the relevant parameters to the sub-template.

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

ExpressionEngine News!

#eecms, #events, #releases