• 夺命雷公狗---Smarty NO:07 内建函数(sysplugins)


    1、capture函数

    功能:捕获一段内容,但不输出

    基本语法:

    {capture name=’变量名称’}

    内容

    {/capture}

    调用:

    {$smarty.capture.变量名称}

    demo4.html示例代码:

    <!DOCTYPE html>
    <html>
    <head>
    <meta charset=’utf-8′>
    <title></title>
    </head>
    <body>
    {capture name=’study’}
    <h1>学习smarty</h1>
    <div>学习smarty是一件快乐的事</div>
    {/capture}
    {$smarty.capture.study}
    </body>
    </html>

    demo4.php示例代码:

    <?php
    require “smarty/Smarty.class.php”;
    $smarty = new Smarty();
    $smarty -> display(“demo4.html”);

    2、config_load函数

    功能:读取配置文件信息

    基本语法:

    {config_load  file=“file”section=“section”}

    参数说明:

    file:要读取配置文件名称

    section:section节(类似局部变量)

    demo4.html示例代码:

    <!DOCTYPE html>
    <html>
    <head>
    <meta charset=’utf-8′>
    <title></title>
    </head>
    <body>
    {config_load file=”config.conf” section=”php”}
    {#title#}
    或
    {$smarty.config.title}
    </body>
    </html>

    config.conf示例代码:

    title=Hello Smarty

    [php]
    title=Hello PHP

    3、include_php函数

    功能:载入php页面到指定的变量中

    基本语法:

    { include_php file=“file”assign=“var”once=“true|false”}

    参数说明:

    file:要载入php页面

    assign:载入成功后,赋予其值到var变量中

    once:是否只载入一次

    注:在3.0版本中,此方法已废弃,如想使用此功能,可以使用SmartyBC.class.php进行加载。

    demo4.php示例代码:

    <!DOCTYPE html>
    <html>
    <head>
    <meta charset=’utf-8′>
    <title></title>
    </head>
    <body>
    {include_php file=”date.php” assign=”var”}
    当前事件:{$var}
    </body>
    </html>

    demo4.php

    <?php
    require “smarty/SmartyBC.class.php”;
    $smarty = new SmartyBC();
    $smarty -> display(“demo4.html”);
    date.php
    <?php
    echo date(“Y-m-d H:i:s”);

    4、insert函数

    功能:实现对Smarty进行扩充

    基本语法:

    { insert name=“func” assign=“var” [var …] }

    但是定义func函数时,一定要按照如下格式进行定义:

    function insert_func(){……}

    demo4.php示例代码:

    <?php
    require “smarty/Smarty.class.php”;
    $smarty = new Smarty();
    function insert_func(){
    echo “hello world!!!”;
    }
    $smarty -> display(“demo4.html”);

    demo4.html示例代码

    <!DOCTYPE html>
    <html>
    <head>
    <meta charset=’utf-8′>
    <title></title>
    </head>
    <body>
    扩展函数:{insert name=”func”}
    </body>
    </html>
  • 相关阅读:
    ny2 括号配对问题
    ny14 会场安排问题
    杭电ACM题目分类
    hdoj2037 今年暑假不AC
    ny37 回文字符串
    算法 字符串的排列组合
    手撸IoC
    Java设计模式
    多种方法求java求整数的位数
    二叉树之 二叉树深度
  • 原文地址:https://www.cnblogs.com/leigood/p/5033093.html
Copyright © 2020-2023  润新知