Smarty preg_match?
Blogs20112011-10-29
Smarty preg_match?
Smarty is a view layer libray, not good at string process. However, when Smarty templates become complex, such case is inevitable.
When use smarty to do regular express, smarty transfer the task to PHP, like this:
{if preg_match("/.pdf$/", $v)}
<a href="{$m.Path}" title="{$v|escape:'html'}" target="_blank">
{$v|escape:'html'}
</a>
{else}
<a href="{$m.Path|escape:'html'}" title="{$m.Path}" target="_blank" >
<img src="{$m.Path}" style="max-height:50px;max-width:110px;" />
</a>
{/if}In latest Smarty version 3.0.4, it works, and the result is correct. However, for performance, leave the string process to PHP as much as possible.
