Smarty Forum Index Smarty
The discussions here are for Smarty, a template engine for the PHP programming language.

{strip}, |strip as configuration

 
Post new topic   Reply to topic    Smarty Forum Index -> Feature Requests
View previous topic :: View next topic  
Author Message
Jerc
Smarty Rookie


Joined: 26 Jan 2010
Posts: 30
Location: Slovenia / Ljubljana

PostPosted: Wed Oct 22, 2014 7:26 am    Post subject: {strip}, |strip as configuration Reply with quote

All our templates starts and ends with {strip}{/strip} tag. When I have to debug something I have remove {strip}{/strip} and |strip tags from the template. It takes a lot of time to find whats wrong with the html/js code.

I suggest to add new configuration:
$smarty->setStrip(int stripLevel);

stripLevel:
0: default value - don't change any template
1: auto strip all variables with |strip modifier
2: auto strip templates - no need to add in the template {strip}{/strip} tags
3: auto strip templates and variables - no need to add in template {strip}{/strip} and use modifier strip on all variables
4: debug mode - skip all {strip}{/strip} and |strip tags


Is it possible to add something like this?
Back to top
View user's profile Send private message
U.Tews
Administrator


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

PostPosted: Wed Oct 22, 2014 10:00 pm    Post subject: Reply with quote

To run the strip modifer on all variables you can do
Code:
$smarty->default_modifiers = array('strip');

See http://www.smarty.net/docs/en/variable.default.modifiers.tpl
So you could control the strip modifier here.

Instead of using {strip}{/strip} tag you could write a prefilter plugin with that functionality and activate it like
Code:
$smarty->autoload_filters = array('pre' => array('stripfilter'));

See http://www.smarty.net/docs/en/advanced.features.prefilters.tpl
See http://www.smarty.net/docs/en/variable.autoload.filters.tpl
See http://www.smarty.net/docs/en/plugins.prefilters.postfilters.tpl

Note that $smarty->default_modifiers and $smarty->autoload_filters will effected the compiled templates. Whenever you modify their values you must force a recompile.

Maybe this could solve your request with existing functionalities.
Back to top
View user's profile Send private message
Jerc
Smarty Rookie


Joined: 26 Jan 2010
Posts: 30
Location: Slovenia / Ljubljana

PostPosted: Thu Oct 23, 2014 1:02 pm    Post subject: Reply with quote

It works.
I only had to fix few JS lines (replace { } with {ldelim}{rdelim}).

This is my function:
Code:
function smarty_prefilter_stripFilter($source, $template)
{
    // copied from smarty_internal_templateparser.php :: yy_r13()
    return preg_replace('![\t ]*[\r\n]+[\t ]*!', '', $source);
}

// autoload
$smarty->autoload_filters = array('pre' => array('stripFilter'));
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Smarty Forum Index -> Feature Requests 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