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>

  • 相关阅读:
    K8s 使用 nfs-client-provisioner
    MySQL IF CASE 例子
    Nginx 限速
    Python 元组操作
    Python if, while,for,continue,break,三目运算符
    Centos7 安装 pyenv
    MySQL 查看大事务
    Tomcat 修改日志路径及日志分割
    游戏攻略 美少女万华镜5
    自建远程桌面过程 vnc + frp
  • 原文地址:https://www.cnblogs.com/hcbin/p/2073134.html
Copyright © 2011-2022 走看看