Smarty template simple configuration and usage example, smarty template example_PHP tutorial

WBOY
Release: 2016-07-12 08:50:41
Original
972 people have browsed it

Examples of simple configuration and usage of Smarty templates, examples of smarty templates

The examples in this article describe the simple configuration and usage of Smarty templates. Share it with everyone for your reference, the details are as follows:

Create templates, templates_c, configs, cache directories in the Smarty directory. So that Smarty can compile and cache it.

Create the smarty_inc.php file to configure smarty as follows:

<&#63;php
include_once("./smarty/Smarty.class.php"); //包含smarty类文件
$smarty = new Smarty(); //建立smarty实例对象$smarty
$smarty->caching=false; //开发是不建议开启缓存
$smarty->template_dir="./templates";  //设置模板目录
$smarty->compile_dir="./templates_c";  //设置编译目录
$smarty->cache_dir="./cache";  //缓存文件夹
$smarty->cache_lifetime=60;
$smarty->left_delimiter = "<{";  //左定界符
$smarty->right_delimiter = "}>"; //右定界符
&#63;>

Copy after login

Run the test and create the index.php file in the root directory:

<&#63;php 
include("smarty_inc.php");
$val= array("丁庆","董丹凤","情侣");
$smarty->assign("name",$val);
$smarty->display("index.html");
&#63;>

Copy after login

Create the index.html template under templates:

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset="utf-8">
<title>测试页面</title>
</head>
<body>
<{foreach from=$name item=x}>
数组内容:<{$x}> <br/>
<{/foreach}>
</body>
</html>

Copy after login

Okay, you’re done, it’s that simple.

For more content related to Smarty, please check out the special topics on this site: "Basic Tutorial for Getting Started with Smarty Templates", "Summary of PHP Template Technology", "Summary of PHP Database Operation Skills Based on PDO", "Summary of PHP Operations and Operator Usage", "Summary of PHP Network Programming Skills", "Introduction Tutorial on PHP Basic Syntax", "Introduction Tutorial on PHP Object-Oriented Programming", "Summary of PHP String Usage", "Introduction Tutorial on PHP MySQL Database Operation" and "php Common Databases" Summary of operating skills》

I hope this article will be helpful to everyone’s PHP program design based on smarty templates.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1133105.htmlTechArticleSmarty template simple configuration and usage examples, smarty template examples This article describes the simple configuration and usage of Smarty templates. Share it with everyone for your reference, the details are as follows: In...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template