国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > PHP > 正文

php中smarty實現多模版網站的方法

2024-05-04 23:36:10
字體:
來源:轉載
供稿:網友

這篇文章主要介紹了php中smarty實現多模版網站的方法,可實現smarty動態選擇模板的功能,需要的朋友可以參考下

本文實例講述了php中smarty實現多模版網站的方法。分享給大家供大家參考。具體實現方法如下:

模板model1.htm代碼:

 

 
  1. <html>  
  2. <head>  
  3. <title>模板1</title>  
  4. </head>  
  5. <body>  
  6. <a href="?model=1" mce_href="?model=1">模板1</a> |  
  7. <a href="?model=2" mce_href="?model=2">模板2</a> |  
  8. <a href="?model=3" mce_href="?model=3">模板3</a>  
  9. <p align=CENTER><font color=RED>{$title}</font></p>  
  10. <hr>  
  11. {$content}  
  12. </body>  
  13. </html> 

模板model2.htm代碼:

 

 
  1. <html>  
  2. <head>  
  3. <title>模板2</title>  
  4. </head>  
  5. <body>  
  6. <a href="?model=1" mce_href="?model=1">模板1</a> |  
  7. <a href="?model=2" mce_href="?model=2">模板2</a> |  
  8. <a href="?model=3" mce_href="?model=3">模板3</a>  
  9. <p align=CENTER><font color=GREEN>{$title}</font></p>  
  10. <hr>  
  11. {$content}  
  12. </body> 
  13. </html> 

模板model3.htm代碼:

 

 
  1. <html>  
  2. <head>  
  3. <title>模板3</title>  
  4. </head>  
  5. <body>  
  6. <a href="?model=1" mce_href="?model=1">模板1</a> |  
  7. <a href="?model=2" mce_href="?model=2">模板2</a> |  
  8. <a href="?model=3" mce_href="?model=3">模板3</a>  
  9. <p align=CENTER><font color=BLUE>{$title}</font></p>  
  10. <hr>  
  11. {$content}  
  12. </body> 
  13. </html>  

php頁面實現:

 

 
  1. <?php  
  2. require 'libs/Smarty.class.php'//包含Smarty類庫文件  
  3. $smarty = new Smarty; //創建一個新的Smarty對象  
  4. $title = "Test";  
  5. $content = "This is a test!";  
  6. $smarty->assign("title",$title); //對模版中的變量賦值  
  7. $smarty->assign("content",$content); //對模版中的變量賦值  
  8. if(!isset($_GET['model'])) //根據參數選擇不同的模板  
  9. {  
  10. $smarty->display('model1.htm');  
  11. }  
  12. else 
  13. {  
  14. if(file_exists('templates/'.'model'.$_GET['model'].'.htm')) 
  15. //判斷模板文件是否存在  
  16. {  
  17. $smarty->display('model'.$_GET['model'].'.htm');  
  18. }  
  19. else 
  20. {  
  21. echo "模板參數不正確!";  
  22. }  
  23. }  
  24. ?> 

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

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 安塞县| 铜山县| 阿拉善右旗| 上林县| 桓台县| 樟树市| 清苑县| 抚州市| 青海省| 德化县| 雅安市| 农安县| 临沂市| 岑溪市| 什邡市| 宜川县| 金湖县| 佛学| 同仁县| 双峰县| 调兵山市| 定襄县| 大渡口区| 石林| 五家渠市| 碌曲县| 广德县| 北海市| 兴安县| 德令哈市| 大余县| 莱州市| 五寨县| 侯马市| 镇坪县| 蒙阴县| 陇川县| 互助| 海伦市| 五莲县| 洞头县|