Smarty Forum Index Smarty
The discussions here are for Smarty, a template engine for the PHP programming language.

php for {function} is defined more than once in final output

 
Post new topic   Reply to topic    Smarty Forum Index -> Feature Requests
View previous topic :: View next topic  
Author Message
vorapoap
Smarty Rookie


Joined: 22 Dec 2009
Posts: 32

PostPosted: Fri Dec 10, 2010 10:19 am    Post subject: php for {function} is defined more than once in final output Reply with quote

Dear Developer,

I have checked the final output xxx.tpl.php in templates_cache/

I think it is better for the defined {function} via Smarty Template to be rendered in the final .tpl.php file only if it is called. and it shouldn't be defined more than once.

In my application, I have a file called include.global.tpl which is included directly (by pre-filter with file_get_contents) at least two time for each page rendering. This file contains many Smarty {function} definition for use globally in any templates...

Code:
<?php if (!function_exists('smarty_template_function_uiForcePage')) {
    function smarty_template_function_uiForcePage($_smarty_tpl,$params){
...} ?>


Even if you have !function_exists in the output file.. but I think it would be more optimal if such line of code is included only once if possible.

Moreover, the output file also includes those functions that have never been called anywhere.. It is best if the output doesn't include such codes.

Is this possible?

Regards,
Vorapoap L.
Back to top
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Fri Dec 10, 2010 12:40 pm    Post subject: Reply with quote

Don't include your global.tpl with the prefilter and file_get_content.

just use {include file='include.global.tpl'} in the main template to load the library.

See also my answer in your related other topic.
Back to top
View user's profile Send private message
vorapoap
Smarty Rookie


Joined: 22 Dec 2009
Posts: 32

PostPosted: Sun Dec 12, 2010 12:54 am    Post subject: Reply with quote

Ha.. I complete this by making another {block} in a parent template just to include this include.global.tpl and make sure that a child template won't override this.

Thank you very much!!!
(You may ignore my below quote due to my stupidity - we don't have SS here?)


Quote:
Dear U.Tews,

It didn't work at first because I injected this {include..include.global.tpl} using the preFilter. Smarty parses any .tpl including those in {include..} ... so include.global.tpl is also parsed again and again with preFilter and this ended up in recursively overflow.

What I do is to put a special "token" inside include.global.tpl and if this token is found by preFilter, there will be no {include file="include.global.tpl"} into $tpl_source.

Are there any variable accessible by descendant class extending Smarty, so I can check what the file it is parsing? I think this will be useful for some occasion?

Or probably, you can make it so Smarty checks before parsing that is it parsing same file over and over again to avoid such error?
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Smarty Forum Index -> Feature Requests All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP