|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
wiseduck Smarty n00b
Joined: 09 Sep 2007 Posts: 2
|
Posted: Sun Sep 09, 2007 8:20 am Post subject: Check if a template is loaded (or will be loaded) |
|
|
Is there a way to get a list of loaded templates with smarty?
For Example: I want to check if a template is loaded (or will be loaded) and use the result in a conditional statement...
I've tried something like this but I get an error...
{if $smarty->template_exists('navigation.tpl')}
do something here
{/if}
Any ideas on how to do this?
Thanks |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Sun Sep 09, 2007 11:25 pm Post subject: |
|
|
You can not call SMARTY methodes directly within a template.
One possible solution is to use a modifier.
1. Store the following code as modifier.template_exists.php in the plugins directory of SMARTY:
Code: | <?php
function smarty_modifier_template_exists($string)
{
global $smarty;
return $smarty->template_exists($string);
}
?> |
2. Make the $smarty object global in your main script.
3. Use the modifier in your template like this:
Code: | {if "navigation.tpl"|template_exists}
do something here
{/if}
|
|
|
Back to top |
|
wiseduck Smarty n00b
Joined: 09 Sep 2007 Posts: 2
|
Posted: Mon Sep 10, 2007 2:02 am Post subject: |
|
|
Thank you... that's exactly what I needed. |
|
Back to top |
|
|
|
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
|