|
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 |
bimal Smarty Elite
Joined: 19 Apr 2007 Posts: 423
|
Posted: Thu Aug 06, 2009 10:18 pm Post subject: checking a valid template within the template file |
|
|
I was producing a very dynamic output, to allow using non-trusted template files (which may have been defined in the database or somewhere).
Instead of going into errors, I needed to make a trick. I needed to check the validity of a dynamic template name, before I can use it in my application.
Hence, I wrote a small modifier plugin to validate. Later, I used it in the template file. I hope, everything is clear within the code below. Usage example is in the comment.
Code: | <?php
/**
* Checks the presense of a template.
* Usage example:
* {if $page.include_file|valid_template}{include file=$page.include_file}{/if}
*/
function smarty_modifier_valid_template($template_name='')
{
# $smarty is a general assumtion of Smarty variable.
global $smarty;
return($smarty->template_exists($template_name));
}
?> |
|
|
Back to top |
|
bimal Smarty Elite
Joined: 19 Apr 2007 Posts: 423
|
Posted: Thu Aug 06, 2009 10:21 pm Post subject: Nothing serious |
|
|
Please do not take anything too seriously.
Simply: replace $page.include_file with your own variable.
That solves everyting out.
Here are some more usage examples:
* {if $page.include_file|valid_template}{include file=$page.include_file}{/if}
* {if $template_file|valid_template}{include file=$template_file}{/if}
* {if 'profile.tpl'|valid_template}{include file='profile.tpl'}{/if} |
|
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
|