Question

Is it possible to define a variable within an Expression Engine template? If so, how might one go about doing so?

Take the following use case as an example. I'm looking for the proper method for defining the value of the primary_image_found variable.

{primary_image_found = False}
{product_images}
  {if primary_image_found == False and sm_img == ''}
    {primary_image_found = True}
    <img src="{lg_img}" />
  {/if}
{/product_images}
Was it helpful?

Solution

I think you are looking for Preload Text Replacements perhaps?

Define and use a variable for "channels":

{preload_replace:channels="news|reviews"}

{exp:channel:category_heading channel="{channels}"}
        <h1>{category_name}</h1>
        {if category_description != ""}<p>{category_description}</p>{/if}
{/exp:channel:category_heading}

{exp:channel:entries channel="{channels}" limit="10"}
        <h2>{title}</h2>
        {body}
{/exp:channel:entries}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top