简体   繁体   English

SMARTY - 如何显示模板变量

[英]SMARTY - How to display template variables

I've been working with the Smarty Template Engine with display_errors = Off .我一直在使用带有display_errors = Off的 Smarty 模板引擎。 Turning it on, I realize that just leaving:打开它,我意识到刚刚离开:

<li{$page['home']}>...</li>
<li{$page['about']}>...</li>

where,在哪里,

$page['home'] = ' class="current"';
$this->smarty->assign("page", $page);

gives me an error, saying that $page['about'] is not defined.给我一个错误,说$page['about']没有定义。

As of now, I see my options are to either turn display_errors = Off or to do this:截至目前,我看到我的选择是打开display_errors = Off或这样做:

<li{if isset($page['home'])}{$page['home']}{/if}>...</li>
<li{if isset($page['about'])}{$page['about']}{/if}>...</li>

Any reason why I should use one over the other?有什么理由为什么我应该使用一个而不是另一个? Or any better solution?还是有更好的解决方案? Thanks.谢谢。

In short, no difference...简而言之,没有区别...

BUT, it's much safer to define your empty variables as NULL .但是,将空变量定义为NULL会更安全。 This protects you from leftovers, or things coming from other pages that you forgot about later, etc... It's just being safe.这可以保护您免受剩菜的影响,或者您以后忘记的其他页面中的东西等等......这只是安全的。

A lot of people swear by making unused variables (that COULD be set) to NULL before starting to use them.很多人发誓在开始使用之前将未使用的变量(可以设置)设置为 NULL。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM