|
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 |
V Smarty Rookie
Joined: 02 May 2003 Posts: 9 Location: Barcelona (Spain)
|
Posted: Sun May 11, 2003 3:48 pm Post subject: About eval |
|
|
I know the following example hasn't much sense but it applies for something I'm trying to do (multiple language site related):
Code: | {assign var="message" value="hello"}
{assign var="two" value='$message'}
{eval var=$two} |
Shouldn't this print ? Instead it prints ... what's the difference with a simple {$two} then?
Or maybe I'm misunderstanding the use of eval?
Thanks, |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Sun May 11, 2003 4:00 pm Post subject: |
|
|
hmmm. {$two} and {eval var=$two} produce the same result.
Either you want to do this, {assign var="two" value="$message"} or you want an indirect eval of $two to produce the eval of $message in which case you would need to encode $message as {$message} which, AFAIK, there is no really easy way to do in template without using something like capture since you can not have an RDELIM inside of a smarty statement. |
|
Back to top |
|
V Smarty Rookie
Joined: 02 May 2003 Posts: 9 Location: Barcelona (Spain)
|
Posted: Sun May 11, 2003 4:22 pm Post subject: |
|
|
Yes, I'm trying to achieve an indirect eval of $two (just didn't know how to name it before). No easy solution then? I've tried to play with the capture function with no luck |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Sun May 11, 2003 11:14 pm Post subject: |
|
|
ha, I think I made that name up
Can you describe what you are trying to achieve in more detail? I mean the whys, whats and hows. There is likely another more direct (and faster) way of getting the business done. If not, I'll try and detail the laborious ways you can do what you are suggesting to do |
|
Back to top |
|
V Smarty Rookie
Joined: 02 May 2003 Posts: 9 Location: Barcelona (Spain)
|
Posted: Mon May 12, 2003 8:26 am Post subject: |
|
|
Long story make short ...
In detail.php: (Getting hotel facilities)
Code: | ...
$hotel = $db->get_row("SELECT telephone, fax, email, air_condition, tv, sat_tv, minibar, parking, gym, sauna, handicaped, ... FROM hotel WHERE hotel_id = '$id' AND visible = 'true';");
$hib->assign('hotel', $hotel); |
In lang_es.php: (A language file already processed by detail.php)
Code: | $this->assign('lang_telephone', 'Teléfono');
$this->assign('lang_fax', 'Fax');
$this->assign('lang_email','E-mail');
$this->assign('lang_air_condition','Aire acondicionado');
$this->assign('lang_tv','TV en habitación');
$this->assign('lang_sat_tv', 'TV Satélite/cable');
$this->assign('lang_minibar', 'Mini bar');
$this->assign('lang_parking', 'Parking');
$this->assign('lang_gym', 'Gimanasio');
$this->assign('lang_sauna','Sauna');
etc ... |
In detail.tpl: (Showing in a table those facilities having 'checked')
Code: | ...
{foreach key=key item=item from=$hotel}
{if $item == 'checked'}
<td>
{assign var="fac" value="\$lang_$key"}
{eval var=$fac}
</td>
{/if}
{/foreach}
... |
I tried to make it as clear as possible.
Thanks for your help |
|
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
|