Heim  >  Artikel  >  Backend-Entwicklung  >  smarty中能使用php中的标签吗?例如:<if><eq>等等。

smarty中能使用php中的标签吗?例如:<if><eq>等等。

WBOY
WBOYOriginal
2016-10-10 11:56:261282Durchsuche

我自己写的php框架,使用SMARTY作为模板引擎,还用封装php标签吗?

回复内容:

我自己写的php框架,使用SMARTY作为模板引擎,还用封装php标签吗?

smarty 3中可以使用任何php的函数

<code>{$data|json_encode}

{json_encode($data)}

{$data->toString()}</code>

对于if,foreach之类的,smarty自身就有

<code>{if $a == 1}
...
{else}
...
{/if}

{foreach $data as $item}
...
{foreachelse}
...
{/foreach}</code>

如果要自定义modifier,或者函数,标签等,还麻烦查看手册,以及参考文件夹:

<code>smarty/libs/plugins/</code>

比如,可以自定义函数:{template_include file=""}

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn