Home  >  Q&A  >  body text

Is it smart to include labels in the if statement?

I would like to have an if statement (or something that does the following) inside smarty's include tag. I have the following containing tags:

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

My goal is that if field["mask"] = to "", then mask is set to itemType->mask, otherwise it should be set to field["mask"]. However, I can't seem to add an if statement inside the include tag.

P粉850680329P粉850680329236 days ago370

reply all(1)I'll reply

  • P粉231112437

    P粉2311124372024-02-26 17:44:55

    You can use if else condition before including the template file and then pass the mask variable inside the include tag as shown below,

    {if $field['mask'] eq ""}
        {$mask = $itemType->mask}
    {else}
        {$mask = $field['mask']}
    {/if}
    
    {include file="controls/control_input.tpl" mask=$mask}

    reply
    0
  • Cancelreply