[PHP] - Smarty母版使用方法(类似ASP.NET母版)
2011-06-05 14:16
363 查看
来源:http://www.flyy.info/480.html
用过asp.net的母版页的人应该感觉这个东西还是有值得php借鉴的地方。
新出来的 smarty 3 引入了 Template Inheritance 概念,能和asp.net 的母版页实现同样的功能。
Template inheritance example
layout.tpl (parent)
myproject.tpl (child)
mypage.tpl (grandchild)
To render the above use
The resulting output is
用过asp.net的母版页的人应该感觉这个东西还是有值得php借鉴的地方。
新出来的 smarty 3 引入了 Template Inheritance 概念,能和asp.net 的母版页实现同样的功能。
Template inheritance example
layout.tpl (parent)
<html> <head> <title>{block name=title}Default Page Title{/block}</title> {block name=head}{/block} </head> <body> {block name=body}{/block} </body> </html>
myproject.tpl (child)
{extends file='layout.tpl'} {block name=head} <link href="/css/mypage.css" rel="stylesheet" type="text/css"/> <script src="/js/mypage.js"></script> {/block}
mypage.tpl (grandchild)
{extends file='myproject.tpl'} {block name=title}My Page Title{/block} {block name=head} <link href="/css/mypage.css" rel="stylesheet" type="text/css"/> <script src="/js/mypage.js"></script> {/block} {block name=body}My HTML Page Body goes here{/block}
To render the above use
$smarty->display('mypage.tpl');
The resulting output is
<html> <head> <title>My Page Title</title> <link href="/css/mypage.css" rel="stylesheet" type="text/css"/> <script src="/js/mypage.js"></script> </head> <body> My HTML Page Body goes here </body> </html>
相关文章推荐
- JSP中使用SIteMesh实现类似asp.net母版效果
- 使用rewrite 让php 实现类似asp.net 的IHttpModule 进行带参数js文件的参数获取
- ASP.NET#使用母版时,如果要使用js中的getElementById()方法取得某个内容页的元素时要注意的问题
- smarty中常用方法(在php文件中使用) append ,clearallassign, clearassign, fetch ,getconfigvars,gettemplatevars
- asp.net的Request对象使用方法
- 简介使用ASP.NET访问Oracle数据库的方法
- 在PHP中使用ASP.NET AJAX
- ASP.NET 2.0中客户端脚本的使用方法
- Asp.net Url改写方法——使用Routing实现
- 在Asp.Net中使用SmtpMail发送邮件的方法
- ASP.NET六大常用验证控件的使用方法
- Ninject 在 Winform、 Asp.net MVC中结合EntityFramework的使用( 注入同一个DbContext的使用方法) - 原创
- asp.net文本编辑器FCKeditor使用方法详解
- ASP.NET 使用ajaxfileupload.js插件出现上传较大文件失败的解决方法(ajaxfileupload.js第一弹)
- [ASP.NET]static变量和viewstate的使用方法
- 使用asp.net ajax的PageMethods来让客户端代码调用服务器端的方法
- asp.net中使用javascript的方法及区别
- ASP.NET jQuery 食谱25 (使用jQuery UI的Autocomplete方法实现文本框的自动搜索填充功能)
- ASP.NET使用GridView导出Excel实现方法
- asp.net文本编辑器FCKeditor使用方法详解