" />

广州葆元健康生物科技有限公司


php中smarty实现多模版网站的方法

网络编程 php中smarty实现多模版网站的方法 06-21

本文实例讲述了php中smarty实现多模版网站的方法。分享给大家供大家参考。具体实现方法如下:

模板model1.htm代码:

<html> 
 <head> 
  <title>模板1</title> 
 </head>  
 <body> 
 <a href="?model=1" mce_href="?model=1">模板1</a> | 
 <a href="?model=2" mce_href="?model=2">模板2</a> | 
 <a href="?model=3" mce_href="?model=3">模板3</a> 
 <p align=CENTER><font color=RED>{$title}</font></p> 
 <hr> 
 {$content} 
 </body>     
</html> 

模板model2.htm代码:

<html> 
 <head> 
  <title>模板2</title> 
 </head>  
 <body> 
 <a href="?model=1" mce_href="?model=1">模板1</a> | 
 <a href="?model=2" mce_href="?model=2">模板2</a> | 
 <a href="?model=3" mce_href="?model=3">模板3</a> 
 <p align=CENTER><font color=GREEN>{$title}</font></p> 
 <hr> 
 {$content} 
 </body>
</html> 

模板model3.htm代码:

<html> 
 <head> 
  <title>模板3</title> 
 </head>  
 <body> 
 <a href="?model=1" mce_href="?model=1">模板1</a> | 
 <a href="?model=2" mce_href="?model=2">模板2</a> | 
 <a href="?model=3" mce_href="?model=3">模板3</a> 
 <p align=CENTER><font color=BLUE>{$title}</font></p> 
 <hr> 
 {$content} 
 </body>
</html> 

php页面实现:

<?php 
require 'libs/Smarty.class.php'; //包含Smarty类库文件 
$smarty = new Smarty; //创建一个新的Smarty对象 
$title = "Test"; 
$content = "This is a test!"; 
$smarty->assign("title",$title); //对模版中的变量赋值 
$smarty->assign("content",$content); //对模版中的变量赋值 
if(!isset($_GET['model'])) //根据参数选择不同的模板 
{ 
 $smarty->display('model1.htm');     
} 
else 
{ 
 if(file_exists('templates/'.'model'.$_GET['model'].'.htm'))
 //判断模板文件是否存在 
 { 
  $smarty->display('model'.$_GET['model'].'.htm'); 
 } 
 else 
 { 
  echo "模板参数不正确!"; 
 } 
} 
?>

希望本文所述对大家的php程序设计有所帮助。

PHP中的一些常用函数收集
php//===============================时间日期===============================//y返回年最后两位,Y年四位数,m月份数字,M月份英文。d月份几号数字,D星期几英文$date=da

PHP模板引擎smarty详细介绍
php/*一、什么是smartysmarty是一个使用PHP写出来的模板PHP模板引擎,它提供了逻辑与外在内容的分离,简单的讲,目的就是要使用PHP程序员同美工分离,使

PHP中的事务使用实例
php//数据库连接$conn=mysql_connect('localhost','root','');mysql_select_db('test',$conn);mysql_query("SETNAMESGBK");/*支持事务的表必须是InnoDB类型一段事务中只能出现一次:mysql


编辑:广州葆元健康生物科技有限公司

标签:模板,赋值,英文,事务,代码