|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
ff77 Smarty n00b
Joined: 28 Mar 2015 Posts: 3
|
Posted: Sat Mar 28, 2015 1:59 pm Post subject: Source of block functions or similar |
|
|
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 |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
|
Back to top |
|
ff77 Smarty n00b
Joined: 28 Mar 2015 Posts: 3
|
Posted: Mon Mar 30, 2015 5:24 pm Post subject: |
|
|
that's right. could be a solution.
how can I access the functions in my plugin? |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Mon Mar 30, 2015 8:38 pm Post subject: Re: Source of block functions or similar |
|
|
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 |
|
ff77 Smarty n00b
Joined: 28 Mar 2015 Posts: 3
|
Posted: Tue Mar 31, 2015 7:23 pm Post subject: |
|
|
ok thanks.
I need the function assemble is a plugin
how can I make the plugin to use test1 and test2? |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Tue Mar 31, 2015 7:47 pm Post subject: |
|
|
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 |
|
|
|
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
|