Smarty FAQ
This is the product of many hours seeing the same questions coming up over and over again in #smarty. If somebody on #smarty refers you here, you ought to be ashamed of yourself for not doing your share of RTFM ;-P
- Q: I $smarty->assign()ed an object into a Smarty template like this:
$smarty->assign('user',$user);, but when I try to access it like this: {assign var='name' value="{$user->name}"}, it gives me a strange error instead of doing the assignment. What am I doing wrong?
- A: You need to use the right syntax if you expect Smarty to understand you:
{assign var='name' value=$user->name}
- Q: I want to do something like this:
{$a.($b.$c)} where $a and $b are arrays, and $c is an index into $b; it isn't working. What's wrong?
- A: You'll want to use PHP array syntax, there:
{$a.$b[$c]}
- Q: How do I access a template variable from inside a {php} block?
- A: You'll want to access the $smarty->_tpl_vars array, but as brakkvatn points out, $this is the Smarty object when you're inside a template:
{php}echo $this->_tpl_vars['my_variable'];{/php}
Best Viewed with Lynx or Elvis
Copyright (C) 2006-2008 Dave Cohen; permission granted to modify and/or redistribute subject to the terms of the GNU Free Documentation License version 1.2 or later