Smarty template Simple configuration and use Method Example _php instance

Source: Internet
Author: User
Tags php template smarty template

This article illustrates the simple configuration and usage of smarty templates. Share to everyone for your reference, specific as follows:

Create the Templates,templates_c,configs,cache directory in the Smarty directory. For Smarty to compile and cache.

Set up the smarty_inc.php file to configure the Smarty as follows:

<?php
include_once ("./smarty/smarty.class.php");//containing smarty class file
$smarty = new Smarty ();//Create Smarty Instance object $ Smarty
$smarty->caching=false;//development is not recommended to open caching
$smarty->template_dir= "./templates";  Set the template directory
$smarty->compile_dir= "./templates_c";  Sets the compilation directory
$smarty->cache_dir= "./cache";  Cache folder
$smarty->cache_lifetime=60;
$smarty->left_delimiter = "<{";  Left delimiter
$smarty->right_delimiter = "}>"; Right delimiter
?>

Line test, create the index.php file in the root directory:

<?php 
include ("smarty_inc.php");
$val = Array ("Dingqing", "Dongdanfeng", "couple");
$smarty->assign ("name", $val);
$smarty->display ("index.html");
? >

Create a index.html template under Templates:

 
 

Well, that's it, it's that simple.

More about Smarty related content to view the site topics: "Smarty Template Primer Tutorial", "PHP Template Technology Summary", "PHP based on the PDO Operation database Skills summary", "PHP operation and operator Usage Summary", "PHP Network Programming Skills Summary", " Introduction to PHP Basic Grammar, "Introduction to PHP object-oriented programming", "PHP string (String) Usage Summary", "Php+mysql Database Operations Tutorial" and "PHP common database Operation Skills Summary"

I hope this article will help you with the PHP program design based on Smarty template.

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.