{* do this somewhere at the top of your template *}
{assign var="title" value=$title|default:"no title"}
{* if $title was empty, it now contains the value "no title" when you print it *}
{$title}
详情搜索smarty手册中Default Variable Handling
本文介绍如何在Smarty模板引擎中处理默认变量,确保当变量为空时能够赋予其默认值,并正常显示。此方法适用于Smarty模板顶部设置,有助于提高代码的健壮性和易用性。
{* do this somewhere at the top of your template *}
{assign var="title" value=$title|default:"no title"}
{* if $title was empty, it now contains the value "no title" when you print it *}
{$title}
详情搜索smarty手册中
被折叠的 条评论
为什么被折叠?