zoukankan      html  css  js  c++  java
  • Swig--模板引擎

    {% filter uppercase %}
        oh hi, {{ name }}
    {% endfilter %}
    {% filter replace "." "!" "g" %}
        Hi. My name is Paul.
    {% endfilter %}

    在express中使用:

     var swig = require('swig');
    app.engine('html', swig.renderFile);
    app.set('views', './views');
    app.set('view engine', 'html');
    swig.setDefaults({cache: false});
    和ejs相比我觉得有个好处是和html标签嵌套使用的时候,不需要分割;



    语法:
    赋值:{{ }}
    eg:
    <h1>{{name}}</h1>
    {% %}
    if:条件语句
    {% if x %}{% endif %}
    else 和 else if
    {% if foo %}
        Some content.
    {% else if "foo" in bar %}
        Content if the array `bar` has "foo" in it.
    {% else %}
        Fallback content.
    {% endif %}
    for循环
    eg:
    {% for num in foo %}
        <li>{{ num }}</li>
    {% endfor %}
    set:设置一个变量
    eg:
    {% set foo = [0, 1, 2, 3, 4, 5] %} {% for num in foo %}
        <li>{{ num }}</li>
    {% endfor %}
    过滤器:filter:对整个块应用过滤器
    eg:
    {% filter uppercase %}
        oh hi
    {% endfilter %}
    转换为大写字母

    eg: {% filter replace "." "!" "g" %} Hi. My name is Paul. {% endfilter %}
    全局查找,将'.'替换成'!'
     
     
     
     
  • 相关阅读:
    垂直同步
    C++ RAII
    C++ RAII
    LCD刷新率和垂直同步的设置
    ping结果中TTL是什么意思
    垂直同步
    stage.frameRate改变帧频
    ping结果中TTL是什么意思
    stage.frameRate改变帧频
    ping 命令的原理,揭开单向“Ping”通的奥秘
  • 原文地址:https://www.cnblogs.com/fangyinghua/p/7681032.html
Copyright © 2011-2022 走看看