|
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 |
SunWuKung Smarty Rookie
Joined: 20 Sep 2008 Posts: 25
|
Posted: Sat May 17, 2014 9:18 am Post subject: modifying template source from block function |
|
|
Hi,
I would like to get and modify the whole template from a block function.
How can I do that?
The story:
My block function manipulates fine the content of an xml tag.
However there is a style defined for that tag in the template prior to that in the xml and I would like to change that as well. As I am working with a WYSIWYG editor I will not be able to separately put a smarty tag on the style.
this is the content that the block function gets
Code: | <draw:frame draw:style-name="fr1" ...>....</draw:frame> |
I can get the style name 'fr1' from here.
Somewhere before that in the template the style is defined like this:
Code: | <style:style style:name="fr1" ...">....</style:style> |
I would need to get the content of the template to find the style element and modify it and put it back to the template source.
Thanks for the help.
SWK |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
|
Back to top |
|
SunWuKung Smarty Rookie
Joined: 20 Sep 2008 Posts: 25
|
Posted: Sat May 17, 2014 11:13 am Post subject: |
|
|
Unfortunately that wouldn't work because I need to get the id from the block first to find the part I need to processes. |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
|
Back to top |
|
SunWuKung Smarty Rookie
Joined: 20 Sep 2008 Posts: 25
|
Posted: Sat May 17, 2014 1:04 pm Post subject: |
|
|
Thanks for the help, that might work.
If I understand it the idea is:
Code: |
function smarty_block_myfunction($params, $content, $smarty, $repeat) {
...do things with block $content
$id = id_from_block
$smarty->registerFilter("output", do_things_wih_template);
return $content
}
|
1. How can I pass parameters to this filter? (eg. the id I got?)
2. smarty_block_myfunction could be called multiple times in a template, will it register multiple output filters with different parameters |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Sat May 17, 2014 1:46 pm Post subject: |
|
|
In the output filter you can read template varibales.
Code: | $value = $template->getTemplateVars('foo'); |
Or use regex in the filter to get the name from the 'draw:style-name="fr1"'. |
|
Back to top |
|
SunWuKung Smarty Rookie
Joined: 20 Sep 2008 Posts: 25
|
Posted: Sat May 17, 2014 10:24 pm Post subject: |
|
|
The output filter sounds good.
I think i will try to put the info that i get in the block into the smarty object, than get them in the filter. Thanks for the help. |
|
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
|