在smarty模板系统中使用if / else?

时间:2014-03-01 16:50:52

标签: php smarty

我刚开始使用smarty模板系统,希望有人可以帮我解决这个问题。

如果{$clientsdetails.customfields1}为空或空白,我希望它显示消息“不工作”。如果在该字段中输入了任何内容,我希望它显示消息“当前正在工作”。

2 个答案:

答案 0 :(得分:1)

试试这个:

{if empty($clientsdetails.customfields1)}
    <p>Not Working</p>
{else}
    <p>Currently Working</p>
{/if}

这将检查$ clientsdetails.customfields1是否未设置或是否等于false。

在PHP中,所有这些都被认为是错误的:

  • 0
  • 0.0
  • “”
  • “0”

如果未设置或== false,则会显示“Not Working”,否则显示“Currently Working”

更多信息的文档:http://www.smarty.net/docs/en/language.function.if.tpl

答案 1 :(得分:0)

试试这段代码:

{if $clientsdetails.customfields1==""}
    not working
{else}
    currently working
{/if}