How to Use variables in smarty include file

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.