Lazlo
Lazlo

Reputation: 8790

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 I assigned in my PHP file.

Upvotes: 1

Views: 3092

Answers (3)

akond
akond

Reputation: 16060

In Smarty 3 there is a better way to do this. Check out the Template Inheritance. This is much more convenient than {include}.

Upvotes: 1

zim32
zim32

Reputation: 2619

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.

Upvotes: 0

Chris Eberle
Chris Eberle

Reputation: 48795

Just use the {include} directive.

http://www.smarty.net/docsv2/en/language.function.include.tpl

Upvotes: 4

Related Questions