英文:
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['mask'] eq ""}
{$mask = $itemType->mask}
{else}
{$mask = $field['mask']}
{/if}
{include file="controls/control_input.tpl" 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="controls/control_input.tpl"
{if $item Type->mask}
mask=$item Type->mask
{else}mask=$field['mask']{/if}
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论