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

Access $smarty object from plugin function

 
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 -> Plugins
View previous topic :: View next topic  
Author Message
zodeus
Smarty n00b


Joined: 13 Jan 2005
Posts: 2
Location: Vancouver

PostPosted: Thu Jan 13, 2005 7:01 pm    Post subject: Access $smarty object from plugin function Reply with quote

I have this function written by AZTEK. I need the xml file to load a different lang based on a user.

Code:

function t($string, $args = array()) {
  //this line needs to change
   $lang_xml_file = "core/languages/ex.xml";

   // expample
   // $lang_xml_file = "core/languages/".$smarty->env->current_language.".xml";

   if(file_exists($lang_xml_file)) {
      $xml = getXmlTree($lang_xml_file);
   } else {
      return strtr($string, $args);
   }

   foreach($xml[0]['children'] as $tag) {
      if($tag['tag'] == "MESSAGE") {
         if($tag['children'][0]['value'] == $string) {
            if($tag['children'][1]['value'] != "") {
               return strtr($tag['children'][1]['value'], $args);
            }
         }
      }
   }

   return strtr($string, $args);
}


Now I've tried this, but the $smarty var is empty (no object)?

Code:

function smarty_block_t($params, $string, &$smarty) {
   foreach($params as $key => $value) {
      $params["%$key"] = $value;
      unset($params[$key]);
   }
   //recursivly lists arrays and object, $smarty is empty
   traverse($smarty);
   print(t($string, $params, $smarty));
}

// new function call
// function t($string, $args = array(), &$smarty) {


My end code is this...

Code:

$lenv  = new Environment;
$user = new Authentication($env);
$smarty = new SmartyEnv($env);
// env adds a bunch of vars one of them being
// $smarty->env->current_lang
Back to top
View user's profile Send private message Send e-mail Visit poster's website
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 -> Plugins 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