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

Source of block functions or similar

 
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
ff77
Smarty n00b


Joined: 28 Mar 2015
Posts: 3

PostPosted: Sat Mar 28, 2015 1:59 pm    Post subject: Source of block functions or similar Reply with quote

hi,
I would give the opportunity to create blocks of code smarty I can recall (source) in my plugin to assemble them and then process them with smarty.
how can I do?
thank you.

es. Define code...
Code:
{chunk name="test01"}
   <div class="{$class}">{$content}</div>
{/chunk}
{chunk name="test02"}
   <ul class="{$class}">{$content}</ul>
{/chunk}


Call plugin
Code:
{examplePlugin $div="test01" $ul="test01"}
Back to top
View user's profile Send private message
U.Tews
Administrator


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

PostPosted: Sun Mar 29, 2015 5:51 pm    Post subject: Reply with quote

Have a look at the {function} tag
See http://www.smarty.net/docs/en/language.function.function.tpl
Back to top
View user's profile Send private message
ff77
Smarty n00b


Joined: 28 Mar 2015
Posts: 3

PostPosted: Mon Mar 30, 2015 5:24 pm    Post subject: Reply with quote

that's right. could be a solution.
how can I access the functions in my plugin?
Back to top
View user's profile Send private message
U.Tews
Administrator


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

PostPosted: Mon Mar 30, 2015 8:38 pm    Post subject: Re: Source of block functions or similar Reply with quote

ff77 wrote:

I would give the opportunity to create blocks of code smarty I can recall (source) in my plugin to assemble them and then process them with smarty.


What exactly shall you plugin do?
Template functions can only be accessed from template source, not form plugin code.

But perhaps this example helps:
Code:
{function name='test1'}
some code
{/function}
{function name='test1'}
some code
{/function}

{function  name='assemble'}
{call name=$div}
some code
{call name=$ul}
...
{/function}


{call name='assemble' div='test1' ul='test2'}
or
{assemble div='test1' ul='test2'}
Back to top
View user's profile Send private message
ff77
Smarty n00b


Joined: 28 Mar 2015
Posts: 3

PostPosted: Tue Mar 31, 2015 7:23 pm    Post subject: Reply with quote

ok thanks.
I need the function assemble is a plugin
how can I make the plugin to use test1 and test2?
Back to top
View user's profile Send private message
U.Tews
Administrator


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

PostPosted: Tue Mar 31, 2015 7:47 pm    Post subject: Reply with quote

Currently there is no way to directly call a template function from a plugin.

But here is workaround

plugin
Code:
function smarty_function_examplePlugin ($params, $template) {
   $template->assign('func', $params['div']);
   $res1 = $template->fetch('string:{call name=$func}');
...
   $template->assign('func', $params['ul']);
   $res2 = $template->fetch('string:{call name=$func}');
....
}


$res1 and $res2 will contain the rendered results of the template functions.
Depending on the real function of the plugins there might be other more optimized solutions.
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 -> 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