0
I have a question related to the Smarty 3.1 template engine, I’m trying to use the {php}{/php} tags in the templates and I’m getting the following error:
Fatal error: Uncaught --> Smarty Compiler: Syntax error in template "file:/var/www/html/Caf/view/index.tpl" on line 67 "{php}" {php}{/php} tags not allowed. Use Smartybc to enable them <-- thrown in /var/www/html/Caf/lib/Smarty/Smarty/libs/sysplugins/smarty_internal_templatecompilerbase.php on line 67
I know that if I use the Smartybc class instead of Smarty it will work normally, but I saw that this is a deprecated method in version 3.1 and that the Smartybc class is an adaptation class.
My question is: Since using the {php}{/php} tags is deprecated, what would be the correct way to execute php code in the templates in this new version?
Would be using the plugins Register https://www.smarty.net/docs/en/api.register.plugin.tpl ?
I tried to use the plugins Register with the getPage method of my routes class and it didn’t work
class
class Rotas {
public static $pag;
private static $dir_controller = 'controller';
private static $dir_view = 'view';
static function getPage() {
if (isset($_GET['pag'])) {
$pagina = $_GET['pag'];
self::$pag = explode("/", $pagina);
$pagina = 'controller/' . self::$pag[0] . '.php';
if (file_exists($pagina)) {
include $pagina;
} else {
include 'error.php';
}
}
}
static function getUrlBase() {
return $_SERVER['DOCUMENT_ROOT'] . '/' . Config::APP_DIR;
}
static function getUrlHome() {
return Config::APP_URL . '/' . Config::APP_DIR;
}
static function getTemplate() {
return self::getUrlHome () . '/' . self::$dir_view;
}
}
I’m trying to use it like this:
$smarty->registerPlugin("function", "getPage", Rotas::getPage());