如何在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.

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.

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