How can I use nested templates with Smarty?
I tried some ways, but they either threw a SmartyException or the nested templates didn't have access to the variables 开发者_Python百科I assigned in my PHP file.
Just use the {include}
directive.
http://www.smarty.net/docsv2/en/language.function.include.tpl
In Smarty 3 there is a better way to do this.
Check out the Template Inheritance. This is much more convenient than {include}
.
Smarty 3 http://www.smarty.net/docs/en/api.create.template.tpl
You should use
string createTemplate(string template,
string cache_id,
string compile_id,
object parent);
Where parent param is your parent template
parent is an optional parameter. It is an uplink to the main Smarty object, a user-created data object or to another user-created template object. These objects can be chained. The template can access only variables assigned to any of the objects in the parent chain.
精彩评论