Re: [SMARTY] eval in smarty

[email protected] (Marcus Bointon) Fri, 16 Mar 2007 10:13:47 +0000
Newsgroups php.smarty.general
Message-ID <[email protected]>
On 14 Mar 2007, at 00:00, Wiwid Lukiyanto wrote:

> <td align="left" colspan="2">{eval var=$message}</td>

As has been said, eval is evil. There's another way - don't generate  
any output text in your php, handle it entirely in the template:

<td align="left" colspan="2">{if !empty($message)}
{if $message == "#register_success#"}{#register_success#}
{elseif $message == "#inputs_empty#"}{#inputs_empty#}
{elseif $message == "#password_not_match#"}{#password_not_match#}
{/if}
{/if}</td>

Not quite so pretty, but solves the problem without eval, and keeps  
content out of your PHP. I do similar things in some of my templates,  
but I tend to use numeric status codes to simplify the syntax:

<td align="left" colspan="2">{if $message}
{if $message == 1}{#register_success#}
{elseif $message == 2}{#inputs_empty#}
{elseif $message == 3}{#password_not_match#}
{/if}
{/if}</td>

This is a bit like what boots suggested when he said to 'assign  
actual content', but it avoids the 'view in controller' problem that  
suggests.

Marcus
-- 
Marcus Bointon
Synchromedia Limited: Creators of http://www.smartmessages.net/
UK resellers of info@hand CRM solutions
[email protected] | http://www.synchromedia.co.uk/