开发者

SMARTY - How to display template variables

I've been working with the Smarty Template Engine with display_errors = Off. 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.

As of now, I see my options are to either turn display_errors = Off or to do this:

<li{if isset($page['home'])}{$page['home']}{/if}>...</li>
<li{if isset($pag开发者_C百科e['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. 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜