Re: using assigned vars in loaded configs?

From: Date: Tue, 04 Mar 2003 21:15:22 +0000
Subject: Re: using assigned vars in loaded configs?
References: 1  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-8406@lists.php.net to get a copy of this message
Hi, I had the same problem and I solved this with the following plugin I wrote : <?php /* * Smarty plugin * ------------------------------------------------------------- * Type: modifier * Name: printf * Purpose: Modifier that gets a format and uses vsprintf * to put an array of arguments into this format. * This can be very useful for multi-lingual sites * that needs to translate sentences that contain * template variables on different places. * Author: Franky Braem * ------------------------------------------------------------- */ function smarty_modifier_sprintf($string) { if ( func_num_args() > 1 ) { $args = func_get_args(); return vsprintf($string, array_slice($args, 1)); } return $string; } ?> Drop this script in the plugins directory. An example on how to use it: In a config file I have: EMAIL_SENT=Email is sent to %1$s In a template file: {#EMAIL_SENT#|sprintf:"<strong>$email</strong>"} This will show the content of $email in the config var and output it as bold in HTML. You can use as many variables as you want, and you can change the position in the config var by using the %1$s syntax. Franky. "Thomas Seifert" <thomas.seifert@myphorum.de> wrote in message news:20030301152535.4af1ddc4.thomas.seifert@myphorum.de... > Is there a way to use vars assigned before in config-files? > > i.e. I use config-files as language-files and these contain outgoing mail-messages. > how could I include then the title of the current page into the mail-message if its > stored completely in the config-file? > > TIA, > > Thomas

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