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

Check if a template is loaded (or will be loaded)

 
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 -> Tips and Tricks
View previous topic :: View next topic  
Author Message
wiseduck
Smarty n00b


Joined: 09 Sep 2007
Posts: 2

PostPosted: Sun Sep 09, 2007 8:20 am    Post subject: Check if a template is loaded (or will be loaded) Reply with quote

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
View user's profile Send private message
U.Tews
Administrator


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

PostPosted: Sun Sep 09, 2007 11:25 pm    Post subject: Reply with quote

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
View user's profile Send private message
wiseduck
Smarty n00b


Joined: 09 Sep 2007
Posts: 2

PostPosted: Mon Sep 10, 2007 2:02 am    Post subject: Reply with quote

Thank you... that's exactly what I needed.
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 -> Tips and Tricks 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