如果语句在include标签内,smarty?

huangapple go评论56阅读模式
英文:

If statement inside include tag, smarty?

问题

我想在Smarty的include标签中使用一个if语句(或者可以实现以下功能的东西)。我有以下的include标签:

{include
file="controls/control_input.tpl"
//一些其他的Smarty变量
mask=$itemType->mask
mask=$field['mask']
}

我的目标是如果field["mask"]等于"",那么将mask设置为itemType->mask,否则将其设置为field["mask"]。然而,似乎我无法在include标签内使用if语句。

英文:

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.

答案1

得分: 1

你可以在包含模板文件之前使用if else条件,然后在include标签内传递mask变量,就像这样:

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-html -->

{if $field['mask'] eq ""}
    {$mask = $itemType->mask}
{else}
    {$mask = $field['mask']}
{/if}

{include file="controls/control_input.tpl" mask=$mask}

<!-- end snippet -->
英文:

You can use if else condition before including template file and then pass mask variable inside include tag like this,

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-html -->

{if $field[&#39;mask&#39;] eq &quot;&quot;}
    {$mask = $itemType-&gt;mask}
{else}
    {$mask = $field[&#39;mask&#39;]}
{/if}

{include file=&quot;controls/control_input.tpl&quot; mask=$mask}

<!-- end snippet -->

答案2

得分: 0

你可以在 include 语句内部使用 if else 条件语句。

{include 
 file="controls/control_input.tpl"
        {if $item Type->mask}
        mask=$item Type->mask
        {else}mask=$field['mask']{/if}
        }
英文:

You can use if else condition inside include statement

{include 
 file=&quot;controls/control_input.tpl&quot;
        {if $item Type-&gt;mask}
        mask=$item Type-&gt;mask
        {else}mask=$field[&#39;mask&#39;]{/if}
        }

huangapple
  • 本文由 发表于 2023年2月16日 18:51:17
  • 转载请务必保留本文链接:https://go.coder-hub.com/75471195.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定