smarty教程-smarty入门基础应用实例教程

采用smarty编写的程序可以获得最大速度的提高,这一点是相对于其它的模板引擎技术而言的。

*/

 代码如下 复制代码

$servername  = 'localhost';
$dbname='whois';//数据库教程名称,需修改为您当前使用的库名称
$tbname='post';//数据表名称,不用修改
$name='root';//数据库用户名,需修改
$password='xxxxxxx';//数据库链接密码,需修改
require_once '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->caching = false;
$db=mysql教程_connect($servername,$name,$password)or die ('服务器连接错误。');
$ii=mysql_select_db("$dbname")or die("不能选择数据库");
mysql_query("set names 'gbk'");

$title ='smarty 教程';
$keyword ='smarty模板,smarty教程';
$description ='提供简单的smarty入门教程';
$smarty->assign('title',$title);
$smarty->assign('keyword',$keyword);
$smarty->assign('description',$description);

$smarty->display('index.html'); //使用 smarty emplates emplatesindex.html 模板

?>

index.html模板文件

 代码如下 复制代码

<title><!--{$title}--></title>
<meta name="keywords" content="<!--{$keyword}-->" />
<meta name="description" content="<!--{$description}-->" />

{include file='head.tpl'}
{include_php file='body.php'}
{include file='footer.tpl'}

<?
/*
smarty 模板变量

.{$name}: 模板变量,smarty中的核心组成,采用smarty定义的左边界符{与右边界符}包含着、以PHP变量形式给出,在smarty程序中将使用
$smarty->assign("name", "李晓军");将模板中的$name替换成“李晓军”三个字。

*/

时间: 2024-05-20 23:42:51

smarty教程-smarty入门基础应用实例教程的相关文章

asp fso教程:asp move文件移动实例教程

move移动方法移至指定的文件或文件夹从一个位置到另一个位置. 语法 FileObject.Move(destination) FolderObject.Move(destination) Parameter Description destination Required. Where to move the file or folder. Wildcard characters are not allowed 对文件操作简单例子. <% dim fs,f set fs=Server.Crea

php教程:PHP number_format ( )实例教程

php教程:PHP number_format ( )实例教程 定义和用法 该number_format ( )函数的格式了一些与分组数千人. 语法 number_format(number,decimals,decimalpoint,separator) number 必需的.数量进行格式化.如果没有其他参数的设置,将一些不格式化小数和逗号( , )作为分隔数以千计. decimals 任择.指定多少个小数.如果这个参数设定的数目将格式化一个点( . )作为小数点. decimalpoint

javascript入门教程:类的使用实例教程

下面我们来看个简单的js基础入门教程吧,类的使用创建修改等哦,javascript入门教程,创建,js教程,入门,javascript实例化 <script language="JavaScript" type="text/javascript"> <!-- var obj={}; //定义了一个空对象 var user={  name:"jack",  //定义了name属性,初始化为jack  favoriteColor:[

JQuery入门基础小实例(1)_jquery

先展示一下这个例子实现的效果: 页面刚刚加载的时候,显示如图所示: 当在文本框中输入数据后,文本框的红色标识消失,如图所示: 点击确定按钮后,会通过后台来向页面输出数据,如图所示: 前台的代码如下(asp.net): <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> <

PHP基础教程(php入门基础教程)一些code代码_php基础

在此教程之前,我就不长篇一律的说什么PHP的常用了. 关于什么是变量呀什么是判断语句呀什么的,请自行查询相关资料此教程值针对于有编程基础,且对PHP陌生的人看.文章比较简单.主要看结构.详细的还请大家自己多多研究 PHP环境安装: PHP通常组合是 :MySql+PHP+Apche 也有 IIS+PHP+MySQL或SqlServer 当然我们可以进行选择组合包来进行安装. 新手建议装AppServ或phpnow等. iis下可以用这个安装运行一下就支持php了,mysql需要安装一下. 也可以

mybaits入门(含实例教程和源码)

版权声明:本文为博主原创文章,转载注明出处http://blog.csdn.net/u013142781 目录(?)[+] 前言:mybatis是一个非常优秀的存储过程和高级映射的优秀持久层框架.大大简化了,数据库操作中的常用操作.下面将介绍mybatis的一些概念和在eclipse上的实际项目搭建使用. 一.mybatis的概念介绍 1.1.背景介绍 MyBatis 是支持普通 SQL查询,存储过程和高级映射的优秀持久层框架.MyBatis 消除了几乎所有的JDBC代码和参数的手工设置以及结果

Maven入门(含实例教程)

原文地址:http://blog.csdn.net/u013142781/article/details/50316383 Maven这个个项目管理和构建自动化工具,越来越多的开发人员使用它来管理项目中的jar包.接下来小宝鸽,将从下面几个方向介绍maven: (1)Maven简单介绍 (2)Maven安装与配置 (3)Maven携手eclipse构建项目 (4)Maven的常用命令 (5)Maven实例 猿友门抓紧了,马上起飞了: (1)Maven的简单介绍 Maven这个个项目管理和构建自动

php基础教程 php内置函数实例教程_php基础

所以爱微网现在讲解先php内置函数 有大小写转换相关函数 文本html标签处理函数 大小写有关函数 复制代码 代码如下: strtolower() strtoupper() ucfirst() ucword() HTML标签相关的字符串格式化函数 复制代码 代码如下: nl2br() htmllentities() htmlspecialchars() stripslashes() strip_tags() number_format() strrev() md5() 在php中所有字符串处理函

教程/dreamweaver/入门 Dreamweaver 4 简明教程2(初步认识 Dreamwe

dreamweaver|教程 Dreamweaver的启动 Dreamweaver的安装过程非常简单,一但成功安装后,就可以在开始菜单找到Dreamweaver的选项: 编辑窗口 第一次启动Dreamweaver,首先看到的是Dreamweaver的编辑窗口,千万别给上面密密麻麻的浮动窗口吓倒,其实常用的,就以下几个: ① 主菜单:在这里可以找到编辑窗口的的绝大部分功能: ② 工具栏:是Dreamweaver4的新增功能: ③ 对象面板(Objects):在网页编辑的过程中,通过单击对象面板的按