zoukankan      html  css  js  c++  java
  • 6月5日 smarty变量调节器 函数 配置文件

    变量调节器:

    1.capitalize[首字符大写]

    main.php:

    <?php
    include("../init.inc.php");
    smarty->assign("attr","hello word");
    smarty->display("main.html");

    main.html:

    <body>
    
    <div><{$attr|capitalize}></div>
    
    </body>

    2.truncate[截取字符串]

    运用同上,

    truncate:30  截取字符长度30

    truncate:30:"..."  第二个参数  截取30 字符,最后三个用...代替,也可以写其他

    3.自己写变量调节器

    把字体颜色变成绿色:

    modifier.fontcolor.php://格式不能变

    <?php
    function smarty_modifier_fontcolor($str,$color='green')
    {
       return "<span style='color:{$color}'>{$str}</span>";
    }

    main.html:

    <body>
    
    <div><{$attr|fontcolor}></div>
    
    </body>

    变量调节器可以组合使用

     函数;

    1.<{literal}>中间内容原样输出<{/literal}>

    2.html_select_date:日期下拉框

    <div><{html_select_date start_year='1990' end_year='2020' momth_format='%m'}></div>

    3.block textarea.php:块方法,需要开始和结束,编辑器

    <{textarea name='txt' toolbar='full' color='yellow' height='300'}>

    <{/taxtarea}>

    需要js

    4.自己写函数

    function.typename.php

    <?php
    function smarty_function_typename($arges)
    {
       $code = $args["code"];
    if($code==0)
    {
    return "单选题";
    }
    else
    {
    return "多选题";
    } }

    main.html

    <div><{typename code=$v[5]}></div>//传参数

     5.块函数:开始结束各调用一次方法

    main.php

    <{fontstyle color='yellow'}>
    
    <a>提交</a>
    
    <{/fontstyle}>

    block.fontstyle.php

    <?php
    function smarty_block_fontstyle($args,$content,$smarty,$a)
    {
    $color = $args["color"]; if(!$a)//结束时
    {
    return "<span style='color:{$color}'>{$content}</span>";
    }
    }

     配置文件:

    main.html

    <{config_load file="style.conf" setion="one"}>//加载页面 
    <
    div style='color:<{#color#}>'>配置文件</div>//用#读取color值

    style.conf://配置文件

    [one]//相同名区分

    color=red

    [two]

    color=yellow

  • 相关阅读:
    江西财经大学第一届程序设计竞赛 I 题 小P和小Q
    江西财经大学第一届程序设计竞赛 H题- 小P的数学问题
    C# 窗体
    数据库操作(对战游戏)
    数据库操作 (数据操作类)
    练习
    泛型集合
    数据库操作 (防注入攻击)
    数据库操作(增删改)
    DO.NET操作数据库
  • 原文地址:https://www.cnblogs.com/dongqiaozhi/p/5564999.html
Copyright © 2011-2022 走看看