Re: Hack to print defines

From: Date: Fri, 21 Sep 2001 18:58:13 +0000
Subject: Re: Hack to print defines
References: 1  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-1513@lists.php.net to get a copy of this message
This doesn't seem like a good idea to me -- you are basically violating the separation of data/logic/presentation. It's not that tough to assign constants to Smarty by using get_defined_constants(), that is, if you _really_ need to do it. On Fri, 21 Sep 2001, Anders Janson wrote: > Hello! > > I needed to output several strings defined in PHP, such as: > define("FOO","This is FOO"); > > Having to assign lots of Smarty variables would have kept me busy > for a while... > So I coded a Q&D hack to give me a new functionality. In my templates, > I can now write : > {=FOO} > > If FOO is defined when the template executes, it will print out the > defined string, otherwise do nothing. This was very useful for me, > and if anybody else wants it, it's an easy patch in Smarty_Compiler. > class.php.... > > function _compile_tag($template_tag) > { > // PATCH insert these lines: > // Anders 2001-09-21, Handle "defines" > if ($template_tag{0} == '=') { > $def = substr($template_tag ,1); > return "<?php if(defined('$def')){echo $def;} ?>"; > } > // End of PATCH > > Perhaps a future version of Smarty could allow us to use global, > defined constants? Perhaps even handled exactly as a Smarty variable, > using modifiers, being able to use them as arguments to functions > etc? > > Until then, have fun with this hack ;) > > /Anders Janson > > > > > > > > --- > You are currently subscribed to smarty as: andrei@ispi.net > To unsubscribe send a blank email to $subst('Email.Unsub') > Visit Smarty's homepage at > http://www.phpinsider.com/php/code/Smarty/ -Andrei If you find a job that you love, you'll never work another day in your life. - Mark Jackson

« previous php.smarty.general (#1513) next »