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

include_once in templates?

 
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 -> Feature Requests
View previous topic :: View next topic  
Author Message
AllKnightAccess
Smarty Rookie


Joined: 02 Mar 2005
Posts: 16

PostPosted: Wed Mar 02, 2005 10:17 pm    Post subject: include_once in templates? Reply with quote

{include} works in templates, but {include_once} does not. is it not supported?
Back to top
View user's profile Send private message Visit poster's website
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Wed Mar 02, 2005 10:24 pm    Post subject: Reply with quote

No, but it doesn't make much sense in a template. What is the purpose?
Back to top
View user's profile Send private message Visit poster's website
AllKnightAccess
Smarty Rookie


Joined: 02 Mar 2005
Posts: 16

PostPosted: Wed Mar 02, 2005 10:56 pm    Post subject: Reply with quote

to do the same as the php function. to just include a file once. at times where i have no caching on pages, many templates on the same page may include the same file. so, i just want the file to be included only one time, rather than have multiple instances of the file being included in the output.
Back to top
View user's profile Send private message Visit poster's website
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Wed Mar 02, 2005 11:04 pm    Post subject: Reply with quote

Quote:
many templates on the same page may include the same file


Can you give an example of this? I can't think of a reason to setup your templates in this manner, but maybe an example would help. It might be more of a design issue than a need for include_once.
Back to top
View user's profile Send private message Visit poster's website
AllKnightAccess
Smarty Rookie


Joined: 02 Mar 2005
Posts: 16

PostPosted: Wed Mar 02, 2005 11:22 pm    Post subject: Reply with quote

Example:

On one particular non-cached page, 2 templates are displayed at the same time. Both of the templates include the same javascript. Include once is needed, so the same javascript is not outputed twice. It is only needed to be included once.
Back to top
View user's profile Send private message Visit poster's website
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Wed Mar 02, 2005 11:56 pm    Post subject: Reply with quote

In that case, wouldn't it be more appropriate to include the javascript as an external link in the document's <head> ?
Back to top
View user's profile Send private message
AllKnightAccess
Smarty Rookie


Joined: 02 Mar 2005
Posts: 16

PostPosted: Thu Mar 03, 2005 2:12 am    Post subject: Reply with quote

Yes, that would be more appropriate, but I need to leave it in the template. So, I guess I can create my own include_once plugin, since one doesn't exist already.
Back to top
View user's profile Send private message Visit poster's website
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Thu Mar 03, 2005 4:37 am    Post subject: Reply with quote

Remember to clear out any cache or stack that you are maintaining at the end of a display() or fetch() and it should be fairly easy to do.
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 -> 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