Smarty Forum Index Smarty
The discussions here are for Smarty, a template engine for the PHP programming language.
Dedicated server web hosting provided by Guru-host.eu.
Prefilter cache

 
Post new topic   Reply to topic    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
kataxxx
Smarty Rookie


Joined: 08 Apr 2012
Posts: 10

PostPosted: Sat Apr 21, 2012 3:26 pm    Post subject: Prefilter cache Reply with quote

Hei.
I want to have more compact cache files. They contain many whitespaces => more memory.
I have this code that is not working right:

Code:
function smarty_prefilter_pre($output, &$smarty)
{
   $output = str_replace(
      array("\t", "\n")
   , '', $tpl_output);
   $output = preg_replace('/class=[\'"][ ]*(\w*)[ ]*[\'"]/', 'class=$1', $output);
   $output = preg_replace('/class=[\'"][\'"]/', '', $output);
   return $output;
}


and:

$this->_smarty->loadFilter('pre','pre');
echo smarty_prefilter_pre($this->_smarty->fetch($tpl, $cache_id));

If I do something like
Code:
function smarty_prefilter_pre($output, &$smarty)
{
   echo $output;
   return $output;
}

No output is displayed.
Thanks!


Last edited by kataxxx on Wed Apr 25, 2012 4:39 pm; edited 2 times in total
Back to top
View user's profile Send private message
rodneyrehm
Administrator


Joined: 30 Mar 2007
Posts: 698
Location: Germany, border to Switzerland

PostPosted: Sat Apr 21, 2012 10:48 pm    Post subject: Reply with quote

Code:
function smarty_prefilter_pre($output, &$smarty) {
$output = str_replace(… $tpl_output);

"$output" !== "$tpl_output"

You should also note that you are stripping all kinds of whitespace you might not really want to strip. Have a look at outputfilter.trimwhitespace.php (in your plugins directory).
_________________
Twitter
Back to top
View user's profile Send private message Visit poster's website
kataxxx
Smarty Rookie


Joined: 08 Apr 2012
Posts: 10

PostPosted: Wed Apr 25, 2012 3:23 pm    Post subject: Reply with quote

rodneyrehm wrote:
Code:
function smarty_prefilter_pre($output, &$smarty) {
$output = str_replace(… $tpl_output);

"$output" !== "$tpl_output"

You should also note that you are stripping all kinds of whitespace you might not really want to strip. Have a look at outputfilter.trimwhitespace.php (in your plugins directory).

Yeah, that's wrong.
That's because of the fact that i copied and paste.
I edited my post, but my problem is still unsolved.
I need an output cache-filter if you could understand me. I also want to gzip the files cached, with a function that I want to create and add to this output cache-filter.
Do you falllow me?

PS: Thanks for the plugin name.


Last edited by kataxxx on Wed Apr 25, 2012 4:39 pm; edited 1 time in total
Back to top
View user's profile Send private message
U.Tews
Administrator


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

PostPosted: Wed Apr 25, 2012 4:21 pm    Post subject: Reply with quote

Note that prefilter run before a template gets compiled it does not help at all for your case.

Use an output filter.
Why does outputfilter.trimwhitespace.php not do the job?

Filters which are loaded exceute automatically.
Quote:
echo smarty_prefilter_pre($this->_smarty->fetch($tpl, $cache_id));
is sort of nonesense.

Just try
Code:

$this->_smarty->loadFilter('output','trimwhitespace');
$this->_smarty->display($tpl, $cache_id);
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    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