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}
有帮助吗?

解决方案

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}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top