View previous topic :: View next topic |
Author |
Message |
theallan Smarty n00b
Joined: 07 Jun 2010 Posts: 2
|
Posted: Mon Jun 07, 2010 9:22 am Post subject: unknown modifier "escape" |
|
|
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 |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Mon Jun 07, 2010 1:35 pm Post subject: |
|
|
do any of your modifiers work? you could have the config_dir setting wrong. |
|
Back to top |
|
theallan Smarty n00b
Joined: 07 Jun 2010 Posts: 2
|
Posted: Mon Jun 07, 2010 2:48 pm Post subject: |
|
|
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 |
|
elpy Smarty n00b
Joined: 14 Sep 2015 Posts: 1
|
Posted: Mon Sep 14, 2015 8:30 am Post subject: |
|
|
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 |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Mon Sep 14, 2015 6:50 pm Post subject: |
|
|
Wrap. Don't extend. |
|
Back to top |
|
auggiedoggie Smarty Rookie
Joined: 30 Mar 2008 Posts: 6
|
Posted: Fri Sep 09, 2016 8:21 pm Post subject: I'm still getting this. |
|
|
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 |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Fri Sep 09, 2016 8:35 pm Post subject: |
|
|
The most likely cause is that you override Smarty plugins directory. |
|
Back to top |
|
elpmis Smarty Elite
Joined: 07 Jun 2007 Posts: 321
|
|
Back to top |
|
|