View previous topic :: View next topic |
Author |
Message |
AllKnightAccess Smarty Rookie
Joined: 02 Mar 2005 Posts: 16
|
Posted: Wed Mar 02, 2005 10:17 pm Post subject: include_once in templates? |
|
|
{include} works in templates, but {include_once} does not. is it not supported? |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Wed Mar 02, 2005 10:24 pm Post subject: |
|
|
No, but it doesn't make much sense in a template. What is the purpose? |
|
Back to top |
|
AllKnightAccess Smarty Rookie
Joined: 02 Mar 2005 Posts: 16
|
Posted: Wed Mar 02, 2005 10:56 pm Post subject: |
|
|
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 |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Wed Mar 02, 2005 11:04 pm Post subject: |
|
|
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 |
|
AllKnightAccess Smarty Rookie
Joined: 02 Mar 2005 Posts: 16
|
Posted: Wed Mar 02, 2005 11:22 pm Post subject: |
|
|
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 |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Wed Mar 02, 2005 11:56 pm Post subject: |
|
|
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 |
|
AllKnightAccess Smarty Rookie
Joined: 02 Mar 2005 Posts: 16
|
Posted: Thu Mar 03, 2005 2:12 am Post subject: |
|
|
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 |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Thu Mar 03, 2005 4:37 am Post subject: |
|
|
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 |
|
|