开发者

Smarty Object Property Inside Its PHP Tag

I have an sm开发者_JS百科arty application where a series of addresses are being printed. It has a zip code too so at some point in template I am using.

{foreach item=i from=$members}
{$i.ZIP}
{/foreach}

The above code works though I am strictly making zip codes to 5 digits which I know can be accomplished by the following code.

{foreach item=i from=$members}
substr_replace("00000", {$i.ZIP}, 5 - strlen({$i.ZIP}));
{/foreach}

But the above code doesn't work and gives run time error. Is there something I am missing?


You can't use PHP code in a Smarty template unless you wrap it in {php} tags. In this case, you can avoid that by using string_format.

I think this should do:

{$i.ZIP|string_format:"%05s"}

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜