 |
Smarty
The discussions here are for Smarty, a template engine for the PHP programming language. Dedicated server web hosting provided by Guru-host.eu. |
| View previous topic :: View next topic |
| Author |
Message |
kataxxx Smarty Rookie
Joined: 08 Apr 2012 Posts: 10
|
Posted: Sat Apr 21, 2012 3:26 pm Post subject: Prefilter cache |
|
|
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 |
|
rodneyrehm Administrator

Joined: 30 Mar 2007 Posts: 698 Location: Germany, border to Switzerland
|
Posted: Sat Apr 21, 2012 10:48 pm Post subject: |
|
|
| 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 |
|
kataxxx Smarty Rookie
Joined: 08 Apr 2012 Posts: 10
|
Posted: Wed Apr 25, 2012 3:23 pm Post subject: |
|
|
| 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 |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 4200 Location: Hamburg / Germany
|
Posted: Wed Apr 25, 2012 4:21 pm Post subject: |
|
|
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 |
|
|
|
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
|