开发者

How can I use nested templates with Smarty?

开发者 https://www.devze.com 2023-03-10 10:35 出处:网络
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.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消