Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

functions in parent template (template inheritance)

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Smarty 3
View previous topic :: View next topic  
Author Message
ilyalyu
Smarty Regular


Joined: 03 Nov 2009
Posts: 72

PostPosted: Fri Jul 27, 2012 9:59 pm    Post subject: functions in parent template (template inheritance) Reply with quote

I have around 20 function definitions in parent template. These function definitions are included in each child template, which I think increases compiled templates size and decreases performance.

I tried to move these function definitions to a separate template and include it with {include}. However, in this case I get an error message that says that the function is not defined. I know that I can use {call 'fn'} instead of {fn}, but it is inconvenient.

So, the question: is it possible to move function definitions to a separate template in an efficient way?

For example, there could be {library 'my-functions.tpl'} syntax, where:
1. my-functions.tpl may contain only functions
2. my-functions.tpl is included only once even if there are multiple occurences of {library 'my-functions.tpl'}.
3. functions from my-functions.tpl can be called with short notation (i.e. {fn} instead of {call 'fn'}).
Back to top
View user's profile Send private message
U.Tews
Administrator


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

PostPosted: Sat Jul 28, 2012 8:55 am    Post subject: Reply with quote

The reason why you have to use {call 'fn'} for external defined functions is that the compiler does not see these functions during compilation and the function library may not be loaded at that time. The compiler has to generate different compiled code for the two cases.
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Smarty 3 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