简体   繁体   中英

PHP can't assign smarty variable

I'm trying to assign some variable in smarty using PHP but the smarty variable return NULL. Here is my code :

{php}
$GLOBALS['smarty']->assign("new_var", "somevalue");
{/php}

{$new_var|@var_dump}

The code above will return NULL I don't know what is happening.

Why don't use a PHP file ?

require("application/libraries/Smarty/libs/Smarty.class.php"); // Smarty class Smarty                   
        $smarty = new Smarty();
        $smarty->assign('new_var' => $phpvar);
        $smarty->display('blabla.tpl');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM