Smarty Forum Index Smarty
The discussions here are for Smarty, a template engine for the PHP programming language.

dynamic config variables

 
Post new topic   Reply to topic    Smarty Forum Index -> Smarty Development
View previous topic :: View next topic  
Author Message
smartywanabee
Smarty n00b


Joined: 16 Apr 2004
Posts: 3

PostPosted: Fri Apr 16, 2004 11:24 am    Post subject: dynamic config variables Reply with quote

I have created lang.conf files for a multi language site. For static text this works a treat, however I have also created a message / error handling function which returns messages / errors when a user carries out a process. This uses Smarty sessions

Therefore I assign a session variable and pass it in the message handling template

$KS->addMsg("Update Successful"); // for example

the function inside my smart class which returns the variable looks like this

function addMsg($msg) {
if ($msg != "")
$_SESSION['msgs'][] = array('info' => $msg);
}


My handling template looks like this

{foreach key=key__ from=$smarty.session.msgs item=msg__}
{if $msg__.info}
{$msg__.info}
{/if}
{/foreach}

Is there any easy way of making the text passed via this $msg__.info a dynamic conf variable, for example {#$msg__.info#}

thanks!
Back to top
View user's profile Send private message
smartywanabee
Smarty n00b


Joined: 16 Apr 2004
Posts: 3

PostPosted: Fri Apr 16, 2004 1:00 pm    Post subject: Reply with quote

I posted my question a bit too quick, I should of searched a bit further. But for those interested I solved the problems by implementing CirTap solution here described
http://www.phpinsider.com/smarty-forum/viewtopic.php?t=836

Basically within my message handling I check the language session and call the specific conf file based on the session value. I then retrieve the msg assigned in my PHP from the section specificed and add this to the smarty array.


/**
* function addErrorMsg($msg,$confsection='')
* @param string $msg string to be called from conf file
* @param string $confsection (optional) section to get info from
* @return string|array a value or array of values
*/
function addErrorMsg($msg,$confsection='') {
if ($msg != ""){
if ($_SESSION['lang']=="en")$conf_file = "en.conf";
else $conf_file = "nl.conf";
//new config file & get variable
$CfgFile = new Config_File($this->config_dir);
$msg =& $CfgFile->get($conf_file,$confsection,$msg);
//assign smarty session
$_SESSION['msgs'][] = array('error' => $msg);
}
}


Of course if anyone has any other (easier) solutions please let me know.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Smarty Forum Index -> Smarty Development 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