skip to Main Content

I want to have an if statement (or something that can do the following functionality) inside a include tag in smarty. I have the following include tag:

        {include
        file="controls/control_input.tpl"
         //some other smarty variables
        mask=$itemType->mask
        mask=$field['mask']
        }

my goal is to essentially have mask be set to itemType->mask if field["mask"] is = to "", otherwise it should be set to field["mask"]. However, I am unable to have a if statement inside the include tag it seems.

2

Answers


  1. You can use if else condition inside include statement

    {include 
     file="controls/control_input.tpl"
            {if $item Type->mask}
            mask=$item Type->mask
            {else}mask=$field['mask']{/if}
            }
    
    Login or Signup to reply.
  2. You can use if else condition before including template file and then pass mask variable inside include tag like this,

    {if $field['mask'] eq ""}
        {$mask = $itemType->mask}
    {else}
        {$mask = $field['mask']}
    {/if}
    
    {include file="controls/control_input.tpl" mask=$mask}
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search