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>

  • 相关阅读:
    AtCoder ABC 129F Takahashi's Basics in Education and Learning
    AtCoder ABC 129E Sum Equals Xor
    UVA 511 Do You Know the Way to San Jose?
    UVA 12504 Updating a Dictionary
    [Poi2000] 病毒
    [loj10061] 最短母串
    [Poi2010] Antisymmetry
    校内集训20181003
    校内集训20181001
    校内集训20180925
  • 原文地址:https://www.cnblogs.com/hcbin/p/2073134.html
Copyright © 2011-2022 走看看