首页 > php教程 > php手册 > 正文

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

WBOY
发布: 2016-06-13 09:01:47
原创
2266 人浏览过

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

 模板model1.htm代码:

1

2

3

4

5

6

7

8

9

10

11

12

13

模板1

模板1 |

模板2 |

模板3

{$title}


{$content}

1 2

3

4

5

1

2

3

4

5

6

7

8

9

10

11

12

13

模板2

模板1 |

模板2 |

模板3

{$title}


{$content}

6 7

8

9

1

2

3

4

5

6

7

8

9

10

11

12

13

模板3

模板1 |

模板2 |

模板3

{$title}


{$content}

10 11 12 13
模板1
模板1 | 模板2 | 模板3

{$title}


{$content}
模板model2.htm代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 模板2
模板1 | 模板2 | 模板3

{$title}


{$content}
模板model3.htm代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 模板3
模板1 | 模板2 | 模板3

{$title}


{$content}

php页面实现:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

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 "模板参数不正确!";

}

}

?>

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
<🎜>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.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门推荐
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责声明 Sitemap
PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!