php中smarty實(shí)現(xiàn)多模版網(wǎng)站的方法
本文實(shí)例講述了php中smarty實(shí)現(xiàn)多模版網(wǎng)站的方法。分享給大家供大家參考。具體實(shí)現(xiàn)方法如下:
模板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頁(yè)面實(shí)現(xiàn):
<?php
require 'libs/Smarty.class.php'; //包含Smarty類庫(kù)文件
$smarty = new Smarty; //創(chuàng)建一個(gè)新的Smarty對(duì)象
$title = "Test";
$content = "This is a test!";
$smarty->assign("title",$title); //對(duì)模版中的變量賦值
$smarty->assign("content",$content); //對(duì)模版中的變量賦值
if(!isset($_GET['model'])) //根據(jù)參數(shù)選擇不同的模板
{
$smarty->display('model1.htm');
}
else
{
if(file_exists('templates/'.'model'.$_GET['model'].'.htm'))
//判斷模板文件是否存在
{
$smarty->display('model'.$_GET['model'].'.htm');
}
else
{
echo "模板參數(shù)不正確!";
}
}
?>
希望本文所述對(duì)大家的php程序設(shè)計(jì)有所幫助。
相關(guān)文章
關(guān)于laravel5.5的定時(shí)任務(wù)詳解(demo)
今天小編就為大家分享一篇關(guān)于laravel5.5的定時(shí)任務(wù)詳解(demo),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來(lái)看看吧2019-10-10
基于php的微信公眾平臺(tái)開發(fā)入門實(shí)例
這篇文章主要介紹了基于php的微信公眾平臺(tái)開發(fā)入門,實(shí)例分析了微信公眾平臺(tái)從注冊(cè)、配置方法及接口代碼的實(shí)現(xiàn)技巧,深入淺出,非常具有實(shí)用價(jià)值,需要的朋友可以參考下2015-04-04
PHP中針對(duì)區(qū)域語(yǔ)言標(biāo)記信息的操作
大家都知道Locale 類就是操作區(qū)域語(yǔ)言相關(guān)內(nèi)容的,它無(wú)法被實(shí)例化,所有全部功能方法都是靜態(tài)的。接下來(lái)通過本文給大家分享PHP中針對(duì)區(qū)域語(yǔ)言標(biāo)記信息的操作,需要的朋友參考下吧2021-07-07
Zend Framework教程之Zend_Registry對(duì)象用法分析
這篇文章主要介紹了Zend Framework教程之Zend_Registry對(duì)象用法,結(jié)合實(shí)例形式分析了對(duì)象注冊(cè)表Zend_Registry的具體功能與相關(guān)使用技巧,需要的朋友可以參考下2016-03-03
php中用加號(hào)與用array_merge合并數(shù)組的區(qū)別深入分析
本篇文章是對(duì)php中用加號(hào)與用array_merge合并數(shù)組的區(qū)別進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下2013-06-06

