欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

php簡單smarty入門程序實例

 更新時間:2015年06月11日 11:31:27   作者:zhuzhao  
這篇文章主要介紹了php簡單smarty入門程序,實例分析了smarty模板的配置與使用技巧,需要的朋友可以參考下

本文實例講述了php簡單smarty入門程序。分享給大家供大家參考。具體如下:

首先要有3個文件夾configs、templates、templates_c,在configs文件夾中有一個配置文件:test.conf,代碼:

title = Welcome to Smarty!
cutoff_size = 40
[setup]
bold = true

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

<html> 
  <head> 
    <title>Smarty Test</title> 
  </head> 
  <body> 
    <H1>Hello, {$Name}</H1> 
  </body> 
</html> 

php文件代碼:

<?php 
require 'libs/Smarty.class.php'; //包含Smarty類庫文件 
$smarty = new Smarty; //創(chuàng)建一個新的Smarty對象 
$smarty->assign("Name","Simon"); //對模版中的變量賦值 
$smarty->display('test.htm'); //顯示頁面 
?>

運行后顯示的頁面代碼:

<html> 
  <head> 
    <title>Smarty Test</title> 
  </head> 
  <body> 
    <H1>Hello, Simon</H1> 
  </body> 
</html> 

運行之后,還在templates_c文件夾中生成一個php文件:

<?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> 

這個文件就是瀏覽所顯示出來的效果。

希望本文所述對大家的php程序設計有所幫助。

相關文章

最新評論