Today, when using smarty to build a website, because there is such a need to include file = "Dynamic Path", this requires using variables in the file value. After trying for a long time, we finally solved the problem, I think the method is clever. I have never used it before when I used smarty. I would like to record it here.
The following describes how to use the variable in the include file value!
Include file = {$ path} "header. dwt" or include file = "{$ path} header. dwt"
The above two statements are incorrect. It is not feasible to directly use variables in the template. We can write them in the PHP file. The correct statement is as follows:
You can write this in the PHP file:
$ Header = $ path. 'header. dwt '; $ smarty-> assign ('header', $ header );
In the template file, write:
{Include file = $ header}
Articles you may be interested in
- Use php functions in the smarty template and how to use multiple functions for a variable in the smarty Template
- Smarty template retention variable Summary
- Smarty variable operator Summary
- Solution to the error "event is not defined" prompt in Firefox
- PHP reports Fatal error Allowed memory size of... how should we solve the problem of insufficient memory?
- Smarty template variable operator Summary
- Select into from prompt Undeclared variable... solution to the error
- Summary of common system variables in Thinkphp templates