View previous topic :: View next topic |
Author |
Message |
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Tue Jul 15, 2014 2:04 am Post subject: Plugin (filter) autoload does not work. |
|
|
I'm doing some work, that require contents of the teplate output to be passed through base64 filter.
On the surface, it all looks simple.
Simple plugin
Code: | <?php
/** Smarty base64 encode output filter plugin
*
* @version $Id$
*/
if(is_callable('base64_encode'))
{
function smarty_outputfilter_base64($source, Smarty_Internal_Template $template)
{
$_result = base64_encode($source);
return $_result;
}
} |
simple block
Code: | {setfilter base64} ... {/setfilter} |
but whenever I try to execute the code, I get a message Quote: | Fatal error: Uncaught --> Smarty Compiler: Syntax error in template "..." on line 6 "{setfilter base64}...{/setfilter}" unknown modifier "base64" |
At the same time,
$tpl->loadPlugin('smarty_outputfilter_base64');
execute without a problem. The plugin is loaded, any debug code I throw into it is correctly printed.
Am I doing something wrong? |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Tue Jul 15, 2014 5:18 am Post subject: |
|
|
It is absolutely unclear from documentation, that "filters" are in fact "modifiers". |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Tue Jul 15, 2014 6:11 am Post subject: |
|
|
Also, I can't understand the reasoning behind inability to wrap {include} in {setfilter} ... As it is now, I'm forced to {capture} include first. |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Tue Jul 15, 2014 6:12 pm Post subject: |
|
|
Note that {setfilter} will only affect variable output not plain template text.
{setfilter} does result in different compiled code. So it has no effect on subtemplates. You have to use {setfilter} in the subtemplate as well.
To filter complete template output use an output filter http://www.smarty.net/docs/en/advanced.features.outputfilters.tpl |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Wed Jul 16, 2014 8:22 am Post subject: |
|
|
I haven't found a way to initialize output filter for included template. Is the documentation incomplete? |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Wed Jul 16, 2014 2:06 pm Post subject: |
|
|
Ah, now I understand. You want to filter just one complete subtemplate. Instead of {capture} you can use
Code: | {include file='foo.tpl' assign='foo'}
{setfilter base64}
{$foo}
{/setfilter} |
|
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Wed Aug 06, 2014 11:27 am Post subject: |
|
|
Yes, that sorts the issue. Sort of.
The problem is somewhat inconsistent linefeed handling in Smarty. It is a process of trial and error to determine exact placement of the substitution blocks to produce desired results. |
|
Back to top |
|
monkeygal23 Smarty n00b
Joined: 28 Sep 2014 Posts: 1
|
Posted: Mon Sep 29, 2014 9:57 am Post subject: |
|
|
AnrDaemon wrote: | Yes, that sorts the issue. Sort of.
The problem is somewhat inconsistent linefeed handling in Smarty. This is one of them problems when you try to look and you can sue and you see the page and when try to refresh and it does not load. And even if you are a lawyer you would not know the legal answer and think the problem is on your end. It is a process of trial and error to determine exact placement of the substitution blocks to produce desired results. |
So, is this issue solved?
Last edited by monkeygal23 on Wed Nov 30, 2016 2:00 am; edited 1 time in total |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Tue Sep 30, 2014 3:04 pm Post subject: |
|
|
monkeygal23 wrote: | So, is this issue solved? |
Who you are and which issue you are referring to? |
|
Back to top |
|
|