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)基地:您身边最(zuì)放心的(de)安全(quán)下载站!
您所在的位(wèi)置:首页 > 软件(jiàn) > 编程开发 > 编程工(gōng)具 > smarty模板

smarty模板

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

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

smarty模板KBV红软(ruǎn)基地

smarty模板使用说明

一. 安装KBV红软(ruǎn)基地

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

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

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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"此处DOCTYPEKBV红软基地

声明不全,下午纠结(jié)了好一会,终于看到(dào)了,新手朋友们关注下">KBV红软基地

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

<head>KBV红(hóng)软(ruǎn)基地

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

<title>Smarty</title></head>KBV红软基地(dì)

<body>{#$hello#}</body>KBV红软(ruǎn)基地

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

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

<?phpKBV红软基地

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

$smarty = new Smarty();//设置各(gè)个目(mù)录的路径(jìng),这里(lǐ)是安装的(de)重点KBV红软基地

$smarty->template_dir ="smarty/templates/templates";KBV红(hóng)软基地

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

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

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

//smarty模板有高(gāo)速缓(huǎn)存的功能,如果(guǒ)这(zhè)里是true的话即打开caching,但(dàn)是会造成(chéng)网页不(bú)立即更新(xīn)的问题(tí),当然也(yě)可以通过其他的办法解决KBV红软基地

$smarty->caching = false;KBV红软(ruǎn)基地

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

$smarty->right_delimiter = "#}";KBV红(hóng)软基地

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

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

$smarty->display('index.tpl');?>KBV红软基地(dì)

(3) 执(zhí)行index.php就能看到(dào)Hello World!了(le)。KBV红软基地

二(èr). 赋值KBV红软基(jī)地

在模板文(wén)件中需要替换(huàn)的值用大括号{}括起来,值的前面还(hái)要加$号。例如{$hello}。这里可以是数组,比如(rú){$hello.item1},{$hello.item2}…KBV红软(ruǎn)基地(dì)

而PHP源文(wén)件中只(zhī)需(xū)要一个简单的函数(shù)assign(var , value)。KBV红软基地

简单的例(lì)子(zǐ):KBV红软基地

*.tpl:KBV红软基(jī)地(dì)

*.php:KBV红软基地

$hello[name]= “Mr. Green”;KBV红软基地

$hello[time]=”morning”;KBV红软基地

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

output:KBV红软基地

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

三. 引用KBV红软基地

网站中的网页一般header和footer是可以共用的,所以只要在每个tpl中(zhōng)引(yǐn)用它们就可以(yǐ)了。KBV红软(ruǎn)基地(dì)

示例:*.tpl:KBV红(hóng)软基地

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

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

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

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

精品(pǐn)软件

热(rè)门(mén)关键词

热门软件推荐