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

Plugin (filter) autoload does not work.

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


Joined: 03 Dec 2012
Posts: 1365

PostPosted: Tue Jul 15, 2014 2:04 am    Post subject: Plugin (filter) autoload does not work. Reply with quote

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


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

PostPosted: Tue Jul 15, 2014 2:42 am    Post subject: Reply with quote

You are using a wrong plugin type.

Use modifier smarty_modifier_base64

See http://www.smarty.net/docs/en/language.function.setfilter.tpl
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1365

PostPosted: Tue Jul 15, 2014 5:18 am    Post subject: Reply with quote

It is absolutely unclear from documentation, that "filters" are in fact "modifiers".
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1365

PostPosted: Tue Jul 15, 2014 6:11 am    Post subject: Reply with quote

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


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

PostPosted: Tue Jul 15, 2014 6:12 pm    Post subject: Reply with quote

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


Joined: 03 Dec 2012
Posts: 1365

PostPosted: Wed Jul 16, 2014 8:22 am    Post subject: Reply with quote

I haven't found a way to initialize output filter for included template. Is the documentation incomplete?
Back to top
View user's profile Send private message
U.Tews
Administrator


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

PostPosted: Wed Jul 16, 2014 2:06 pm    Post subject: Reply with quote

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


Joined: 03 Dec 2012
Posts: 1365

PostPosted: Wed Aug 06, 2014 11:27 am    Post subject: Reply with quote

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


Joined: 28 Sep 2014
Posts: 1

PostPosted: Mon Sep 29, 2014 9:57 am    Post subject: Reply with quote

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


Joined: 03 Dec 2012
Posts: 1365

PostPosted: Tue Sep 30, 2014 3:04 pm    Post subject: Reply with quote

monkeygal23 wrote:
So, is this issue solved?

Who you are and which issue you are referring to?
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