简体   繁体   中英

smarty php variable not appearing

I am using the smarty templating system for php. I have the following within a .tpl file:

 <a href=\"{/literal}/view/{$tablename}/

where $tablename is a php variable defined in the php file that calls the .tpl

$tablename = 'string';

However running the script only

href="/view//"

is visible. What am I doing wrong?

This

$tablename = 'string';

is not enough to populate a variable into Smarty.

You need to use

$Smarty->assign("tablename", $tablename);

$Smarty being your initialized Smarty object, of course.

Are you assigning to variable to the smarty instance? eg with assign() ?

 $smarty->assign('tablename', $tablename);

See also the manual page on assigning variables from PHP

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