Home >Backend Development >PHP Tutorial >Smarty environment configuration and usage introductory tutorial, smarty environment introductory tutorial_PHP tutorial

Smarty environment configuration and usage introductory tutorial, smarty environment introductory tutorial_PHP tutorial

WBOY
WBOYOriginal
2016-07-12 08:52:49795browse

Smarty environment configuration and use introductory tutorial, smarty environment introductory tutorial

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

Download Smarty (here takes Smarty-2.6.26 as an example). Unzip the downloaded file (the directory structure is quite complex). Next, I will show you an installation example. After reading it, you should be able to draw inferences.

(1) Create a new directory learn/ in the root directory, and then create a directory smarty/ in learn/. Copy the libs/ of the directory you just decompressed to smarty/, and then create a new templates directory in smarty/, and create cache/, templates/, templates_c/, and config/ in templates.

(2) Create a new template file: index.tpl, and place this file in the learn/smarty/templates/templates directory. The code is as follows:

<!DOCTYPE HTML PUBLIC "-//W3C//DTDHTML 4.01
<html>
<head>
<metahttp-equiv="Content-Type" content="text/html;charset=gb2312">
<title>Smarty</title></head>
<body>{#$hello#}</body>
</html>

Create a new index.php and place this file under learn/:

<&#63;php
require 'smarty/libs/Smarty.class.php';
$smarty = new Smarty;//设置各个目录的路径,这里是安装的重点
$smarty->template_dir ="smarty/templates/templates";
$smarty->compile_dir ="smarty/templates/templates_c";
$smarty->config_dir = "smarty/templates/config";
$smarty->cache_dir ="smarty/templates/cache";
//smarty模板有高速缓存的功能,如果这里是true的话即打开caching,但是会造成网页不立即更新的问题,当然也可以通过其他的办法解决
$smarty->caching = false;
$smarty->left_delimiter = "{#"; //重新定义边界,因为默认边界“{}“符,在html页面中嵌入js脚本文件编写代码段时使用的就是”{}“符,自定义边界符还可以是<{ }>, {/ /} 等
$smarty->right_delimiter = "#}";
$hello = "Hello World!";//赋值
$smarty->assign("hello",$hello);//引用模板文件
$smarty->display('index.tpl');&#63;>

(3) Execute index.php to see Hello World!.

Readers who are interested in more PHP-related content can check out the special topics of this site: "Basic Tutorial for Getting Started with Smarty Templates", "Summary of PHP Template Technology", "Complete of PHP Array (Array) Operation Skills", "PHP Based on PDO Operation" Summary of Database Skills", "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 "Summary of Common PHP Database Operation 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/1125882.htmlTechArticleSmarty environment configuration and use introductory tutorial, smarty environment introductory tutorial This article describes the configuration and use of Smarty environment with examples. Share it with everyone for your reference, the details are as follows: Download S...
Statement:
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