zoukankan      html  css  js  c++  java
  • [PHP] Smarty母版使用方法(类似ASP.NET母版)

    来源:http://www.flyy.info/480.html

    用过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>

  • 相关阅读:
    python开发必备:virtualenv虚拟环境(自用)
    JavaScript经典实例
    javascript事件驱动及事件处理
    在HTML网页中嵌入脚本的方式
    JavaScript数据结构
    JavaScript语言调试技巧
    CSS+DIV布局
    在HTML文档中应用CSS
    CSS常用属性
    定义CSS
  • 原文地址:https://www.cnblogs.com/hcbin/p/2073134.html
Copyright © 2011-2022 走看看