RE: [SMARTY] Embedding variables into parameters for the {include} command

From: Date: Thu, 28 Aug 2003 21:17:19 +0000
Subject: RE: [SMARTY] Embedding variables into parameters for the {include} command
References: 1  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-10146@lists.php.net to get a copy of this message
Well, This should also work, but I don't know what your custom variable modifier does. {include file="header.tpl" title="User Details :: $name"} if the var contains a . (dot) you need to put it in backticks {include file="header.tpl" title="User Details :: $name.key"} ... <title>{$title|htmlentities}</title> ... You chould read this page http://smarty.php.net/manual/en/language.syntax.quotes.php -Marshall ____________________________________ "If at first the idea is not absurd, then there is no hope for it." - Albert Einstein -----Original Message----- From: Richard Jones [mailto:rj@last.fm] Sent: Thursday, August 28, 2003 4:45 PM To: smarty-general@lists.php.net Subject: Re: [SMARTY] Embedding variables into parameters for the {include} command On Thursday 28 August 2003 7:02 pm, Marshall Sorenson wrote: > You don't need brackets to access the variable, and I'm pretty sure you > can't use a variable modifier while assigning. > > Try this instead: > > {include file="header.tpl" title_1="User Details ::" title_2=$name} > > ... > <title>{$title_1} {$title_2|htmlentities}</title> > ... > > -Marshall Hmm, i don't really like the idea of having to split it into 2 parameters, it feels a bit of a dirty hack. i can easily move the modifier (|htmlentities) to the header.tpl file, but i'd still like to be able to pass "User :: $name" or "Blah :: $myObject->someVar" as the "title" parameter any other ways around this? Many thanks, Richard > ____________________________________ > > "If at first the idea is not absurd, > then there is no hope for it." > - Albert Einstein > > > -----Original Message----- > From: Richard Jones [mailto:rj@last.fm] > Sent: Thursday, August 28, 2003 3:42 PM > To: smarty-general@lists.php.net > Subject: [SMARTY] Embedding variables into parameters for the {include} > command > > > Hi all, > I've been using smarty for a couple of months now, and i've run into an > annoying problem.. i'm sure i'm missing an obvious solution.. > > I include a header atop each template, passing it the title to use in the > html > <title> tags > > the title is chosen depending on page content, for example: > > {include file="header.tpl" title="User Details :: {$name|htmlentities}"} > > except this doesn't work.. > > Fatal error: Smarty: [in user.tpl line 1]: syntax error: expecting '=' > after attribute name 'Details' (Smarty_Compiler.class.php, line 1342) in > /usr/local/lib/php/Smarty_Compiler.class.php on line 1824 > > omitting the {} around the embedded variable $name doesnt work either.. i > just > prints the "$name|htmlentities" literally > > There are occasions where i wish to use $userobject->getName() as part of > the > title parameter too.. > > any suggestions? > > Thanks, > > Richard > > -- > Smarty General Mailing List (http://smarty.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php -- Smarty General Mailing List (http://smarty.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php

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