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

modifying template source from block 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 -> General
View previous topic :: View next topic  
Author Message
SunWuKung
Smarty Rookie


Joined: 20 Sep 2008
Posts: 25

PostPosted: Sat May 17, 2014 9:18 am    Post subject: modifying template source from block function Reply with quote

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
View user's profile Send private message
U.Tews
Administrator


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

PostPosted: Sat May 17, 2014 11:04 am    Post subject: Reply with quote

You can use a prefilter the modify the source before compiling.

See http://www.smarty.net/docs/en/advanced.features.prefilters.tpl
Back to top
View user's profile Send private message
SunWuKung
Smarty Rookie


Joined: 20 Sep 2008
Posts: 25

PostPosted: Sat May 17, 2014 11:13 am    Post subject: Reply with quote

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
View user's profile Send private message
U.Tews
Administrator


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

PostPosted: Sat May 17, 2014 11:24 am    Post subject: Reply with quote

Ahh sorry

So then use the outputfilter

See http://www.smarty.net/docs/en/advanced.features.outputfilters.tpl
Back to top
View user's profile Send private message
SunWuKung
Smarty Rookie


Joined: 20 Sep 2008
Posts: 25

PostPosted: Sat May 17, 2014 1:04 pm    Post subject: Reply with quote

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
View user's profile Send private message
U.Tews
Administrator


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

PostPosted: Sat May 17, 2014 1:46 pm    Post subject: Reply with quote

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
View user's profile Send private message
SunWuKung
Smarty Rookie


Joined: 20 Sep 2008
Posts: 25

PostPosted: Sat May 17, 2014 10:24 pm    Post subject: Reply with quote

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
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 -> General 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