When I was using smarty to build a website today, there was a need to include file="dynamic path", which required using variables in the value of file. After trying for a long time, I finally solved it. I think the method is It's quite clever. I've never used smarty like this before, so I'll record it here.
Let’s talk about how to use variables in the value of include file!
include file={$path}"header.dwt" or include file="{$path}header.dwt"
The above two ways of writing are wrong. Using variables directly in the template does not work. We can write it in a php file. The final correct writing is as follows:
You can write this in the php file:
$header=$path.'header.dwt';
$smarty->assign('header',$header);
Copy after login
is written like this in the template file:
{include file=$header}
Copy after login
Articles you may be interested in
- Using php functions in smarty templates and how to use multiple functions for one variable in smarty templates
- Smarty template retained variable summary
- Smarty variable operator summary
- Firefox prompts event is not defined error solution
- PHP reports Fatal error Allowed memory size of...What should I do if there is insufficient memory error? Solution to
- Smarty template variable operator summary
- select into from prompt Undeclared variable.... Error solution
- Summary of system variables commonly used in Thinkphp templates
http://www.bkjia.com/PHPjc/764077.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/764077.htmlTechArticleWhen I was using smarty to build a website today, there was a need to include file="dynamic path". This You need to use variables in the value of file. After trying for a long time, I finally solved it. Since...