We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

preload_replace, doesn't work in a conditional enviroment...

Feature Requests

11Media's avatar
11Media
157 posts
9 years ago
11Media's avatar 11Media

Hi,

Assigning text replacements doesn’t seem to work in an conditional environment, seems like a bug as any multiple instance of trying to define a ‘preload_variable’ falters, even though it’s only getting defined once, depending on which statement is true…

For example, I want to populate my path variable based on the conditionals of the entries of my custom fields…

So if the 2nd segment is ‘fruit’ then it’ll populate the link with the {landing_page} variable… If an landing_page doesn’t exist…it will go to it’s related entry (Company) and see if it has a special landing page… (company_secondary_url)…. if it doesn’t have that…. then it will show the {company_url}…. (which will always be there….

My logic is correct, but the ‘preload_replace’ fails…. So starting to think now this may very well be a bug…

{if segment_2 == 'fruit'}
  {if fruit_landing_page}

    {preload_replace:variable_name="{fruit_landing_page}"}
  {if:else}

    {fruit_company}
      {if fruit_company:company_secondary_url}
        {preload_replace:variable_name="{fruit_company:company_secondary_url}"}
      {if:else}
        {preload_replace:variable_name="{fruit_company:company_url}"}
      {/if}
    {/fruit_company}

  {/if}
{/if}

Link to website: {variable_name}

Good to either get this functionality added, or if anyone can assist as to why it wouldn’t work please enlighten me 😊

       
Ingmar's avatar
Ingmar
29,245 posts
9 years ago
Ingmar's avatar Ingmar

You’d have to use PHP for this, as you can’t assign variables after the fact, so to speak. (In PHP terms they really behave more like constants.) EE preload_replace variables can only be set at the top of the page and then used further on down the line. (To be honest, the “preload” part sort of gives that away.) To dynamically assign variables you’ll need PHP.

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.