Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

About eval

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
V
Smarty Rookie


Joined: 02 May 2003
Posts: 9
Location: Barcelona (Spain)

PostPosted: Sun May 11, 2003 3:48 pm    Post subject: About eval Reply with quote

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
Code:
hello
? Instead it prints
Code:
$message
... what's the difference with a simple {$two} then?
Or maybe I'm misunderstanding the use of eval?

Thanks,
Back to top
View user's profile Send private message
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Sun May 11, 2003 4:00 pm    Post subject: Reply with quote

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
View user's profile Send private message
V
Smarty Rookie


Joined: 02 May 2003
Posts: 9
Location: Barcelona (Spain)

PostPosted: Sun May 11, 2003 4:22 pm    Post subject: Reply with quote

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 Rolling Eyes
Back to top
View user's profile Send private message
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Sun May 11, 2003 11:14 pm    Post subject: Reply with quote

ha, I think I made that name up Smile

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 Wink
Back to top
View user's profile Send private message
V
Smarty Rookie


Joined: 02 May 2003
Posts: 9
Location: Barcelona (Spain)

PostPosted: Mon May 12, 2003 8:26 am    Post subject: Reply with quote

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 Smile
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
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
Protected by Anti-Spam ACP