1
2
3
4 首先要有3个文件夹configs、templates、templates_c,在configs文件夹中有一个配置文件:test.conf,代码:
 
title = Welcome to Smarty!
cutoff_size = 40
[setup]
bold = true

templates中有模板文件:test.htm:

1
2
3
4
5
6
7
8
<html>
<head>
<title>Smarty Test</title>
</head>
<body>
<H1>Hello, {$Name}</H1>
</body>
</html>

php文件代码:

1
2
3
4
5
6
<?php
require 'libs/Smarty.class.php'; //包含Smarty类库文件
$smarty = new Smarty; //创建一个新的Smarty对象
$smarty -> setTemplateDir('./templates/test.htm/');//配置模板
$smarty -> setCompileDir('./templates_c/');//编译后的文件
$smarty->assign("Name","Simon"); //对模版中的变量赋值
$smarty->display('test.htm'); //显示页面
?>

运行后显示的页面代码:

1
2
3
4
5
6
7
8
<html>
<head>
<title>Smarty Test</title>
</head>
<body>
<H1>Hello, Simon</H1>
</body>
</html>

运行之后,还在templates_c文件夹中生成一个php文件:

1
2
3
4
5
6
7
8
9
10
11
12
13
<?php
/* Smarty version 2.6.22, created on 2009-03-19 13:20:00
compiled from test.htm */
?>
<html>
<head>
<title>Smarty Test</title>
</head>
<body>
<H1>Hello, <?php echo $this->_tpl_vars['Name']; ?>
</H1>
</body>
</html>

smarty入门的更多相关文章

  1. smarty 入门2(个人总结)

    1.下载安装: 2.拷贝libs文件夹到web文件夹: 3.引入smarty类文件   // include './libs/Smarty.class.php'; 4.配置smarty      // ...

  2. Smarty入门学习

    --------------------------------- 安装和设置 --------------------------------- require('../Smarty/Smarty. ...

  3. smarty 学习记录

    smarty模版是比较大众化的一个模版,在php开发过程当中被很多开发者视为最友好的模版之一,学习smarty课程对于很多培训机构来说也是列入了培训课程之一,那么很多方面就需要我们学习了一. 安装首先 ...

  4. Smarty3学习笔记

    Smarty3 笔记 By 飞鸿影~ -- :: Smarty入门 1.什么是smarty? Smarty是采用php写的一个模版引擎,设计的目的是要将php代码与html代码分离, 使php程序员只 ...

  5. php100视频原始地址列表整理:

    php100视频原始地址列表整理: 教程名称 . 1:环境配置与代码调试 2:PHP的数据类型与源码调试 3:常用PHP运算类型介绍与应用 4: PHP条件语句介绍与应用 5:PHP循环语句的介绍与应 ...

  6. smarty半小时快速上手入门教程

    http://www.jb51.net/article/56754.htm http://www.yiibai.com/smarty/smarty_functions.html http://www. ...

  7. Smarty快速入门

    1.Smarty是用纯php语言写的类 2.功能是实现前后端分离 3.Smarty简洁高效 4.快速入门案例 1.下载 smarty源码 https://www.smarty.net/ 2.搭建PHP ...

  8. smarty 模板的入门使用

    <?php require_once 'inc/libs/Smarty.class.php'; $s=new Smarty(); // echo $s::SMARTY_VERSION; // e ...

  9. jQuery入门第二天&&&正则表达式完结篇——仿smarty引擎的制作

    hi 周一完全的不在状态...中午还去观战,没有睡觉的我,晚上的smarty不知道能不能做完,加油吧 1.jQuery ---过滤性选择器(二)--- --[attribute=value]属性选择器 ...

随机推荐

  1. sqoop中,如果数据中本身有换行符,会导致数据错位

    sqoop中,如果数据中本身有换行符,会导致数据错位: 解决办法: 在sqoop import时修改配置文件 sudo -u hive sqoop import --connect jdbc:mysq ...

  2. loadrunner获取本机的机器名称

  3. python 线程之_thread

    python 线程之_thread _thread module: 基本用法: def child(tid): print("hello from child",tid) _thr ...

  4. Xamarin.iOS编译出错

    Xamarin.iOS编译出错 错误信息:C:/Program Files(x86)/Reference Assemblies/Microsoft/Framework/Xamarin.iOS/v1.0 ...

  5. [xsd学习]xsd介绍

    一直以来项目中对xml格式的判断使用的都是dtd格式,直到最近才发现,不知何时都已经转为xsd来进行判断和校验,于是今天专门找资料看下,不得不说,对于这类资料的入门,w3cschool真是个不错的资料 ...

  6. 【转】ContextLoaderListener 和 DispatcherServlet

    转载地址: http://www.guoweiwei.com/archives/797 DispatcherServlet介绍 DispatcherServlet是Spring前端控制器的实现,提供S ...

  7. 项目新的需求,网页的自适应交付/响应式交付 Responsive/Adaptive Delivery

    网页为什么要做自适应交付,皆因现在移动设备大行其道,现在是移动互联网时代,以IOS及Android为首的各种移动终端已经遍地开花. 当人家用380px的iphone打开你的网页时,你总不能显示个102 ...

  8. Python基础1-Python环境搭建

    Python环境搭建首先通过终端窗口输入 "python" 命令来查看本地是否已经安装Python以及Python的安装版本: 若未安装则需要下载安装,下面为linux和windo ...

  9. C# 词法分析器(二)输入缓冲和代码定位

    系列导航 (一)词法分析介绍 (二)输入缓冲和代码定位 (三)正则表达式 (四)构造 NFA (五)转换 DFA (六)构造词法分析器 (七)总结 一.输入缓冲 在介绍如何进行词法分析之前,先来说说一 ...

  10. ural 1071. Nikifor 2

    1071. Nikifor 2 Time limit: 1.0 secondMemory limit: 64 MB Nikifor has a number x. He doesn't need it ...