Warning: mkdir(): No space left on device in /www/wwwroot/jx.baidu.com/func.php on line 159

Warning: file_put_contents(./web/hch368.com/cache/f9/ae1cb/7d556.html): failed to open stream: No such file or directory in /www/wwwroot/jx.baidu.com/func.php on line 149
GG扑克

GG扑克




  • 红软(ruǎn)基(jī)地:您身边(biān)最放心的安全下载站(zhàn)!
您所在(zài)的位置:首页 > 软(ruǎn)件 > 编程开(kāi)发 > 编程工具 > smarty模板

smarty模板

软件类(lèi)型:
国外软件
软(ruǎn)件语言:
英文
软(ruǎn)件大小(xiǎo):
332 KB
软件授权(quán):
免费软(ruǎn)件
软件评级(jí):
4
更新(xīn)时间:
2016-06-16
应(yīng)用平台:
WinXP, Win7, WinAll
软件(jiàn)简介

smarty模板是(shì)一个使用PHP写出来的模板引擎(qíng),是目前业界最著名(míng)的PHP模板引(yǐn)擎之一。它(tā)分离了逻辑代码和外在的内容,提供了一种易于管(guǎn)理和使用的(de)方法,用来将原本与HTML代码混杂在(zài)一起PHP代码逻辑分(fèn)离(lí)。简单的讲,目(mù)的就是(shì)要使PHP程(chéng)序员同前端人员分离,使程序员(yuán)改变(biàn)程序(xù)的逻辑(jí)内容不会影响到(dào)前端人(rén)员(yuán)的(de)页面设计,前端人员(yuán)重新修(xiū)改(gǎi)页面不会影响到(dào)程序的(de)程(chéng)序逻辑,这在多人合作(zuò)的项目中显的尤(yóu)为重要。KBV红软基地

smarty模板KBV红(hóng)软基地

smarty模板使用说明

一. 安装(zhuāng)KBV红软基地

下载最新版本(běn)的(de)Smarty。解(jiě)压下载的文件(jiàn)(目录结构还蛮(mán)复杂的)。接下来演示给大(dà)家一个安装实例,看过应该会举一反三的。KBV红软(ruǎn)基(jī)地

(1) 在根目录(lù)下建立(lì)了新的目录learn/,再在(zài)learn/里建(jiàn)立一个目(mù)录smarty/。将刚才解(jiě)压缩出(chū)来的目录(lù)的libs/拷贝到smarty/里(lǐ),再在smarty/里新(xīn)建templates目录,templates里新建cache/,templates/,templates_c/, config/。KBV红软基地

(2) 新建一个模(mó)板文件(jiàn):index.tpl,将此文件放在learn/smarty/templates/templates目录下(xià),代码如下:KBV红软基地

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"此处DOCTYPEKBV红(hóng)软(ruǎn)基地

声明(míng)不全,下午纠结了好一会,终于(yú)看(kàn)到(dào)了,新(xīn)手朋友们关注下">KBV红软基地

<html>KBV红(hóng)软基地

<head>KBV红软基(jī)地

<metahttp-equiv="Content-Type" content="text/html;charset=utf-8">KBV红软基(jī)地

<title>Smarty</title></head>KBV红软基地

<body>{#$hello#}</body>KBV红软基地

</html>KBV红软基地(dì)

新(xīn)建index.php,将此文件放(fàng)在learn/下:KBV红软基(jī)地

<?phpKBV红软基地

require 'smarty/libs/Smarty.class.php';KBV红软基地

$smarty = new Smarty();//设置各个目(mù)录的路径,这里是安装(zhuāng)的(de)重(chóng)点KBV红软基地

$smarty->template_dir ="smarty/templates/templates";KBV红软基地

$smarty->compile_dir ="smarty/templates/templates_c";KBV红软基(jī)地

$smarty->config_dir = "smarty/templates/config";KBV红软(ruǎn)基地

$smarty->cache_dir ="smarty/templates/cache";KBV红软基地

//smarty模板(bǎn)有高速缓存(cún)的功能,如果这里是true的话即打开caching,但(dàn)是(shì)会造成网页不立即更新的问题(tí),当然也可以通过其他的办(bàn)法解决KBV红软基地

$smarty->caching = false;KBV红软基地

$smarty->left_delimiter = "{#"; //重新定义边界,因为默认(rèn)边界“{}“符,在html页(yè)面中嵌入js脚本文(wén)件编写(xiě)代码段时使用的就是”{}“符,自定义边界符(fú)还可以是(shì)<{ }>, {/ /} 等KBV红软基地(dì)

$smarty->right_delimiter = "#}";KBV红软(ruǎn)基地

$hello = "Hello World!";//赋值KBV红软基地

$smarty->assign("hello",$hello);//引用模(mó)板文件KBV红软基地

$smarty->display('index.tpl');?>KBV红(hóng)软基地

(3) 执(zhí)行index.php就能看到Hello World!了。KBV红(hóng)软基地

二. 赋值KBV红(hóng)软基地

在模(mó)板文(wén)件中需要替换(huàn)的值用大括号(hào){}括(kuò)起来,值的前面还要加$号。例如{$hello}。这里(lǐ)可以(yǐ)是数(shù)组,比(bǐ)如{$hello.item1},{$hello.item2}…KBV红软基地

而PHP源(yuán)文件(jiàn)中只(zhī)需要一(yī)个简单(dān)的函数assign(var , value)。KBV红软(ruǎn)基地

简单(dān)的例子:KBV红(hóng)软基地

*.tpl:KBV红软(ruǎn)基地

*.php:KBV红软基地

$hello[name]= “Mr. Green”;KBV红(hóng)软基(jī)地

$hello[time]=”morning”;KBV红软(ruǎn)基地(dì)

$smarty->assign(“exp”,$hello);KBV红(hóng)软基(jī)地

output:KBV红软基地

Hello,Mr.Green!Good morningKBV红软基地

三. 引用KBV红软基地(dì)

网站中的网页一(yī)般header和footer是可(kě)以共用的,所以只(zhī)要(yào)在每(měi)个(gè)tpl中引用它们就可以了。KBV红(hóng)软(ruǎn)基地

示例:*.tpl:KBV红软基地

{include file="header.tpl"}KBV红软基(jī)地

{* body of template goes here *}KBV红软(ruǎn)基地

{include file="footer.tpl"}KBV红软基地

软件(jiàn)下载地址
smarty模板
软(ruǎn)件推荐
下载排行

精品(pǐn)软件

热(rè)门关键词

热(rè)门(mén)软件推荐