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

How to change name of Config VAR

 
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 -> Tips and Tricks
View previous topic :: View next topic  
Author Message
Yegg
Smarty Rookie


Joined: 16 Sep 2003
Posts: 6

PostPosted: Fri Jan 21, 2005 2:14 am    Post subject: How to change name of Config VAR Reply with quote

e.g. I have a config file - where defined some config vars liks

page_title_1="1'st page"
page_title_2="2'd page"
page_title_3="3'd page"

and I have some page id 1, 2 or 3.

in template I want to use code like this:

{#page_title_{$page_id}#}

how to make it working?
_________________
Sorry, for my bad english.
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Fri Jan 21, 2005 3:17 pm    Post subject: Reply with quote

You can use sections:

config file:

Code:
[1]
page_title = 1st page
[2]
page_title = 2nd page
[3]
page_title = 3rd page


template:

Code:
{config_load file="my.conf" section=$page_id}
{#page_title#}
Back to top
View user's profile Send private message Visit poster's website
boots
Administrator


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

PostPosted: Sat Jan 22, 2005 12:38 am    Post subject: Reply with quote

Monte's solution is brilliant. Here is the general hack:

Code:
{assign var=cvar value="page_title_`$page_id`"}
{$smarty.config.$cvar}


see:

http://smarty.php.net/manual/en/language.syntax.quotes.php
http://smarty.php.net/manual/en/language.variables.smarty.php
Back to top
View user's profile Send private message
Yegg
Smarty Rookie


Joined: 16 Sep 2003
Posts: 6

PostPosted: Sat Jan 22, 2005 11:33 am    Post subject: Reply with quote

tnx alot
_________________
Sorry, for my bad english.
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Sjefen
Smarty Rookie


Joined: 01 Apr 2006
Posts: 19

PostPosted: Tue Apr 04, 2006 7:05 pm    Post subject: Hm Reply with quote

I'm trying this sollution, in a template where I loop through an array: {foreach from=$menu item="entry"}. The array elements are displayed with $entry.alt.

When I try getting the variable from the config, for each iteration of the for loop, file like this:

{config_load file="my.conf" section=$entry.alt}
{#page_title#}

I get no result. I checked by replacing "$entry.alt" with the section name (which it should containt), which worked. But using "$entry.alt" won't.

Any ideas?
Back to top
View user's profile Send private message MSN Messenger
boots
Administrator


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

PostPosted: Fri Apr 21, 2006 5:18 pm    Post subject: Reply with quote

Just saw this post.

Please verify that $entry.alt really is the section name. It seems it is not.
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 -> Tips and Tricks 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