RE: format variable if it has been set

From: Date: Thu, 07 Mar 2002 10:41:53 +0000
Subject: RE: format variable if it has been set
Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-2963@lists.php.net to get a copy of this message
There is already e default modifier. IMHO, putting tests like isset in a template just include some unncessary complexity and thus overhead in the template ... > -----Original Message----- > From: Papp, Gyozo [mailto:pgerzson@freestart.hu] > Sent: Thursday, March 07, 2002 11:37 AM > To: smarty@lists.ispi.net > Subject: [smarty] format variable if it has been set > > > Hi, > > what is the most convenient and the shortest way to > format a variable (like using string_format variable modifier) > if and only if the correspondig variable has been set/assigned? > > I know that the following code can do the job: > > {if isset($variable)} > {$variable|string_format:'the value of variable: %s'} > {/if} > > when $variable is set to "Hello" it will display: > > the value of variable: Hello > > but if it's not set, then it results a blank page. > > I come up with a new modifier to reduce the complexity of my > templates, so I'm just wondering if it can be achieved by any > other way ,for example, combining built-in modifiers somehow? > > {$variable|ifformat:'the value of variable: %s'} > > Papp Gyozo > - pgerzson@freestart.hu > > > --- > You are currently subscribed to smarty as: arnaud.limbourg@cegetel.fr > To unsubscribe send a blank email to > $subst('Email.Unsub') > Visit Smarty's homepage at > http://www.phpinsider.com/php/code/Smarty/ >

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