Reputation: 6873
I have an smarty 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?
Upvotes: 0
Views: 178
Reputation: 468
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"}
Upvotes: 1