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

unknown modifier "escape"

 
Post new topic   Reply to topic    Smarty Forum Index -> Smarty 3
View previous topic :: View next topic  
Author Message
theallan
Smarty n00b


Joined: 07 Jun 2010
Posts: 2

PostPosted: Mon Jun 07, 2010 9:22 am    Post subject: unknown modifier "escape" Reply with quote

Hello all,

I've just starting to experiment when Smarty 3 (nice work!) and I've hit an issue when trying to 'escape' a variable. In the template I have:

Code:
{$post.Username|escape}


In the Apache error log I get this:

Quote:
PHP Fatal error: Uncaught exception 'Exception' with message 'Syntax Error in template "/www/smarty/gf/templates/index.tpl" on line 19 "{$post.Username|escape}" unknown modifier "escape"'


Looking in my Smarty directory "plugins/modifier.escape.php" is definitely there, and the error log doesn't have any indication that it can't be read, or not found in a different location.

Am I using incorrect syntax here? It appears to work in Smarty 2 okay (on my colleagues machine), but not in Smarty 3. I'm using RC1.

Many thanks,
Allan[/quote]
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7365
Location: Lincoln Nebraska, USA

PostPosted: Mon Jun 07, 2010 1:35 pm    Post subject: Reply with quote

do any of your modifiers work? you could have the config_dir setting wrong.
Back to top
View user's profile Send private message Visit poster's website
theallan
Smarty n00b


Joined: 07 Jun 2010
Posts: 2

PostPosted: Mon Jun 07, 2010 2:48 pm    Post subject: Reply with quote

Hi mohrt,

Thanks for the reply. Your post promoted me to dig deeper and it appears we ran into a hiccup with a transition from Smarty 2 to Smarty 3. We had a class extending Smarty and that doesn't appear to go down well (probably the initialisation around doing it that way). I've removed that now and it works perfectly.

Many thanks,
Allan
Back to top
View user's profile Send private message
elpy
Smarty n00b


Joined: 14 Sep 2015
Posts: 1

PostPosted: Mon Sep 14, 2015 8:30 am    Post subject: Reply with quote

Old post but got here via google so maybe it helps others;

Had the same issue after upgrading and was extending the class, solved it by simply calling the parent::__construct() method
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1545

PostPosted: Mon Sep 14, 2015 6:50 pm    Post subject: Reply with quote

Wrap. Don't extend.
Back to top
View user's profile Send private message
auggiedoggie
Smarty Rookie


Joined: 30 Mar 2008
Posts: 6

PostPosted: Fri Sep 09, 2016 8:21 pm    Post subject: I'm still getting this. Reply with quote

I'm porting a Smarty 2 -> 3 site and ran into this problem with several of the plugins. I'm extending Smarty but I believe I followed the update instructions properly. I'm running PHP7, if it matters.

Class:
Code:

class TRMS extends Smarty
{
    public $Cookie;
    public $credentials;
    public $dsn;
    public $db;

    function __construct()
    {
        // Class Constructor.
        parent::__construct();

        $this->setTemplateDir($GLOBALS['TRMS']['smarty']['templates']);
        $this->setCompileDir($GLOBALS['TRMS']['smarty']['templates_c']);
        $this->setConfigDir($GLOBALS['TRMS']['smarty']['configs']);
        $this->setCacheDir($GLOBALS['TRMS']['smarty']['cache']);
        $this->setPluginsDir($GLOBALS['TRMS']['smarty']['plugins']);

        $this->initialize();
    }

    private function initialize()
    {
        // We need to fetch the user's credentials cookie to see which
        // database we need to open.
        $this->Cookie = new Cookie;
        ...
      }


It's being instantiated as:
Code:

require_once($_SERVER['TRMS_BASE'] . '/class/trms.class.php');

$trms = new TRMS();


Example of an error:
Code:

     <a class="button"
        href="javascript:void(null)"
        onclick="this.blur();
                 confirm_set_entity_status({$patient_id}, '{$full_name|escape:'quotes'}');
                 return false;">
     <span>Set Patient Active</span></a>


Error log:
Code:
PHP Fatal error:  Uncaught  --> Smarty Compiler: Syntax error in template "file:/web/htdocs/chf/trms/smarty/templates/view_patient.tpl"  on line 66 "confirm_set_entity_status({$patient_id}, '{$full_name|escape:'quotes'}');" unknown modifier "escape" <-- \n  thrown in /web/htdocs/chf/trms/vendor/smarty/smarty/libs/sysplugins/smarty_internal_templatecompilerbase.php on line 66
[/code]


FIXED (and left for reference in case someone else runs into this).

The plugins config needs to be an array which includes the vendor plugins directory:
Code:
        $this->setPluginsDir(array(
            $GLOBALS['TRMS']['smarty']['plugins'],
            $_SERVER['TRMS_BASE'] . '/vendor/smarty/smarty/libs/plugins'
        ));


Last edited by auggiedoggie on Fri Sep 09, 2016 8:49 pm; edited 3 times in total
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1545

PostPosted: Fri Sep 09, 2016 8:35 pm    Post subject: Reply with quote

The most likely cause is that you override Smarty plugins directory.
Back to top
View user's profile Send private message
elpmis
Smarty Elite


Joined: 07 Jun 2007
Posts: 321

PostPosted: Sun Sep 11, 2016 11:45 am    Post subject: Reply with quote

You can addPluginsDir() instead setPluginsDir() for your system

http://www.smarty.net/docs/en/api.add.plugins.dir.tpl
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Smarty Forum Index -> Smarty 3 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