php in the Smarty template to achieve nested

Author:Anonymous    Updated:2008-10-16 18:40:15
Previously used to fasttemplate, all of a sudden contact smarty,
Has not the nested template approach

So try to look forward to the smarty-source and found that in fact do a very good
In Smarty.class.php in such a way to fetch

function fetch ($ resource_name, $ cache_id = null, $ compile_id = null, $ display = false)

His role is to be the ultimate template file displayed in the browser's html code

Look at ways assign the code

function assign ($ tpl_var, $ value = null)
(
if (is_array ($ tpl_var)) (
foreach ($ tpl_var as $ key => $ val) (
if ($ key! ='') (
$ this-> _tpl_vars [$ key] = $ val;
)
)
) Else (
if ($ tpl_var! ='')
$ this-> _tpl_vars [$ tpl_var] = $ value;
)
)

Can be seen from the code, it will label each of the smarty value of the existence of the $ this-> _tpl_vars such an array,
As a result of follow that they add that such a method

/ **
* Nested template approach
*
* @ Param unknown_type $ tpl_var
* @ Param unknown_type $ resource_name
* @ Author VioletElegy
* /
function parse ($ tpl_var, $ resource_name) (
$ this-> _tpl_vars [$ tpl_var] = $ this-> fetch ($ resource_name);
)

The parse method used only when the following as such

$ smarrty-> parse ( "index", "qiantao.tpl");

In this way, the original template file ($ index) tag on the template qiantao.tpl be replaced,
Attention, qiantao.tpl document labels must parse method is called before the assignment

Finally, the method of display is called full-time on the show

This smarty in a very easy to achieve as fasttemplate nested

I understand that, smarty mechanism to allow nested template, but it just did not provide an interface
I was very confused and I see teaching materials, look at the code carefully enough, or by fasttemplate, as well as other template solutions and the impact of heavy smarty does not understand the idea, or is the developer of negligence
Previous:Tomcat configuration of a number of ip binding domain
Next:asp upload voice
User Reviews
Site Search
Recommended article
AD