Simple configuration and usage examples of the Smarty template, and examples of the smarty Template

Source: Internet
Author: User
Tags smarty template

Simple configuration and usage examples of the Smarty template, and examples of the smarty Template

This document describes the simple configuration and usage of the Smarty template. We will share this with you for your reference. The details are as follows:

Create the templates, templates_c, configs, and cache directories in the Smarty directory. So that Smarty can be compiled and cached.

Create a smarty_inc.php file and configure smarty as follows:

<? Phpinclude_once (". /smarty/Smarty. class. php "); // contains the smarty class file $ smarty = new Smarty (); // creates a smarty Instance Object $ smarty-> caching = false; // It is not recommended to enable cache $ smarty-> template_dir = ". /templates "; // set the template directory $ smarty-> compile_dir = ". /templates_c "; // set 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 ("ding Qing", "Dong Danfeng", "couples"); $ smarty-> assign ("name ", $ val); $ smarty-> display ("index.html");?>

Create an index.html Template under templates:

<Html> 

Well, it's just that simple.

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.