Smarty include instance tutorial

Source: Internet
Author: User
Tags foreach

Instance tutorial


<Html>
<Head>
<Title >{$ title }</title>
</Head>
<Body>
{Include file = 'page _ header. tpl '}

{* Body of template goes here, the $ tpl_name variable
Is replaced with a value eg 'contact. Tpl'
*}
{Include file = "$ tpl_name.tpl "}

{Include file = 'page _ footer. tpl '}
</Body>
</Html>

{Include} passing variables

{Include file = 'links. tpl 'title = 'newest link' links = $ link_array}
{* Body of template goes here *}
{Include file = 'footer. tpl 'foo = 'bar '}
 
Output

<Div id = "box">
<H3> {$ title} {/h3>
<Ul>
{Foreach from = $ links item = l}
... Do stuff...
</Foreach}
</Ul>
</Div>

<Body>
{Include file = 'Nav. tpl 'assign = navbar}
{Include file = 'header. tpl 'title = 'smarty is cool '}
{$ Navbar}
{* Body of template goes here *}
{$ Navbar}
{Include file = 'footer. tpl '}
</Body>
 
 
Example 7-20. Various {include} resource examples

{* Absolute filepath *}
{Include file = '/usr/local/include/templates/header. Tpl '}

{* Absolute filepath (same thing )*}
{Include file = 'File:/usr/local/include/templates/header. tpl '}

{* Windows absolute filepath (MUST use "file:" prefix )*}
{Include file = 'File: C:/www/pub/templates/header. tpl '}

{* Include from template resource named "db "*}
{Include file = 'DB: header. tpl '}

{* Include a $ variable template-eg $ module = 'contacts '*}
{Include file = "$ module. tpl "}

{* Wont work as its single quotes ie no variable substitution *}
{Include file = '$ module. tpl '}

{* Include a multi $ variable template-eg amber/links. view. tpl *}
{Include file = "$ style_dir/$ module. $ view. tpl "}
 

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.