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

Compiling the output of a own smarty plugin?

 
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
^peta
Smarty n00b


Joined: 11 Jul 2008
Posts: 4

PostPosted: Sat Jul 12, 2008 7:05 pm    Post subject: Compiling the output of a own smarty plugin? Reply with quote

Hello.

I've got a language engine for smarty. It's registered as a default smarty plugin, and it is used as well.

Actually there is a problem that I want use "smarty-variables" in the output of this language-plugin.

Calling the plugin: {lang item='start.welcoming'}
Output: Welcome {$name}!
Requested output (if the smarty-variable is assigned): Welcome Kasi!

Well, i hope you was able to understand my troubles.
If there is a possibility, i'd prefer a solution like
(plugins output:) return $smarty->compile($report);

Thanks for your dedication Rolling Eyes
Back to top
View user's profile Send private message MSN Messenger
messju
Administrator


Joined: 16 Apr 2003
Posts: 3336
Location: Oldenburg, Germany

PostPosted: Sat Jul 12, 2008 11:18 pm    Post subject: Reply with quote

Maybe have a look in the source of the {eval}-plugin.
And consider making your plugin a compiler function instead of a custom function to avoid repeated recompiling of your text strings.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
^peta
Smarty n00b


Joined: 11 Jul 2008
Posts: 4

PostPosted: Sun Jul 13, 2008 3:59 pm    Post subject: Reply with quote

Hello again.

I tried using the compiler-function.

The function returns (e.g.):
return "\necho 'Welcome {$name}';";

output of the browser:
Welcome {$name}

Well, what I need to do that I get the assigned smarty-variable.?

Thank you.
Back to top
View user's profile Send private message MSN Messenger
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Mon Jul 14, 2008 7:50 pm    Post subject: Reply with quote

return "\necho 'Welcome '.$this->_tpl_vars['name'];";
Back to top
View user's profile Send private message
^peta
Smarty n00b


Joined: 11 Jul 2008
Posts: 4

PostPosted: Mon Jul 14, 2008 11:32 pm    Post subject: Reply with quote

Thank you.

This is an extract of my plugin. It may help any1.

Code:

// ( ... )
      if (eregi('$', $report)) {
        $result=array();
        while ($found = strpos($report, '$', $found)) {
          $found++;
          $result[]=substr($report, $found, strpos($report, ' ', $found)-$found);
        }
        foreach ($result as $value) {
          if (isset($smarty->_tpl_vars[$value])) {
             $report=str_replace('$'.$value, '\'.$this->_tpl_vars[\''.$value.'\'].\'', $report);
          }
        }
      }
// ( ... )
?>
Back to top
View user's profile Send private message MSN Messenger
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