 |
Smarty
The discussions here are for Smarty, a template engine for the PHP programming language. Dedicated server web hosting provided by Guru-host.eu. |
| View previous topic :: View next topic |
| Author |
Message |
bimal Smarty Elite

Joined: 19 Apr 2007 Posts: 419 Location: Kathmandu, Nepal
|
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));
}
?> |
_________________ Skype: pbimal
To hire instantly as a freelancer - https://www.odesk.com/o/profiles/users/_~~657b70cc7f2c616a/
Visit my website - http://bimal.org.np/ for more articles
800+ screenshots to learn about website mistakes: http://mistakes.sanjaal.com/ |
|
| Back to top |
|
bimal Smarty Elite

Joined: 19 Apr 2007 Posts: 419 Location: Kathmandu, Nepal
|
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} _________________ Skype: pbimal
To hire instantly as a freelancer - https://www.odesk.com/o/profiles/users/_~~657b70cc7f2c616a/
Visit my website - http://bimal.org.np/ for more articles
800+ screenshots to learn about website mistakes: http://mistakes.sanjaal.com/ |
|
| 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
|