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.

Re-assigning preload_replace variables?

March 26, 2012 8:16pm

Subscribe [2]
  • #1 / Mar 26, 2012 8:16pm

    Hue Labs

    31 posts

    I’d like to use conditionals to set up a “variable” to use throughout my template. I thought this might work:

    {if segment_2 != 'all'}
      {preload_replace:seg_2="{segment_2}"}
    {if:else}
      {preload_replace:seg_2="nada"}
    {/if}

    Unfortunately, it always sets seg_2 to “nada” regardless of the conditional result. I’m assuming it’s because of the parsing order or such. I’ve tried using plugins such as MX Jumper and Variables with the same results.

    Have I somehow missed an easy way of creating and re-assigning “variables” in EE?

  • #2 / Mar 27, 2012 3:41am

    Enviromed

    375 posts

    Have you tried Freebie?

    http://devot-ee.com/add-ons/freebie

  • #3 / Mar 27, 2012 12:22pm

    Hue Labs

    31 posts

    I have used Freebie, but that it doesn’t help my situation. Basically, I need to be able to set a “variable”, or preload_replace, with the option of re-assigning it later in the template if needed.

    However, it appears preload_replace does not work that way.

  • #4 / Mar 27, 2012 4:47pm

    Dan Decker

    7338 posts

    Hi Hue,

    The behavior you are seeing is the expected outcome. A preload_replace will always reflect the last value encountered, regardless of conditionals. preload_replace are parsed very early in the Parse Order.

    You can use something like Stash to set an get variables, even to the database so they can be used across templates.

    Cheers,

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

ExpressionEngine News!

#eecms, #events, #releases