0

I'm using preload replace to show a specific entry for a user, but the variable always displays the first option in the list. What am I doing wrong?

{exp:user:profile} {categories group_id="5"} {category_body}

{if {category_id} =="10"}{preload_replace:entryId="10"}
{if:elseif {category_id} =="11"}{preload_replace:entryId="9"}
{if:elseif {category_id} =="8"}{preload_replace:entryId="8"}
{if:else}{preload_replace:entryId="7"}{/if}

{/category_body} {/categories} {/exp:user:profile}  
1

None of your conditionals are affecting the value of your preload-replace.

Preload replace processing happens very early in the template parsing engine. The engine simply applies the first value you give. You can't assign preload replace variables dynamically.

From the docs:

ExpressionEngine allows you to assign text to be replaced prior to a template being parsed, to save time typing and editing certain bits of text that might get used multiple times. Preload Replacements act as a straight string replacement for use later in the same template.

I personally have always solved my problems without this add-on, but it seems that most people use Stash as an easy way of getting around and setting variables in templates (which is against the point of a template):

https://github.com/croxton/Stash

Read the Stash docs and maybe it'll work for you, but I would recommend rethinking your execution as I would bet you can just avoid what you're trying to do using the native engine.

| improve this answer | |
  • Thanks, I eventually came to the same conclusion. – Andrew Jan 22 '19 at 15:31
0

As above I decided to put the following in a partial template:

{exp:user:profile} {categories group_id="5"} {category_body}
    {category_id}
{/category_body} {/categories} {/exp:user:profile}

Which allowed me to bring this into the page template:

{if { [name-of-partial-template] }=="10"}

  ...entry_id="10"...

{/if}

And so on

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.