Git Product home page Git Product logo

Comments (3)

PaulGuo avatar PaulGuo commented on July 26, 2024

不建议使用这种语法,<%%>不支持注释的。最好使用Juicer封装的更好用的方式来写,Juicer支持 <%%>是为了兼容之前micro-tmpl的模板,新模板请使用Juicer语法。

${abc} 输出数据
{# 注释内容}

中文文档见:http://juicer.name/docs/docs_zh_cn.html

from juicer.

pulo avatar pulo commented on July 26, 2024

哦 看来还是有一定的限制。
毕竟封装好的方法有一定限制。

其实我要实现的是 在模板里通过传进去的data 定义 一组变量。然后在模板里输出。
比如

<%
var name;
if(data.sex=='man'){//问题就在这里 我没办法获得传进来的data
name="张三";
}else{
name="李四"
}
%>

我的名字叫@{name}

......//其他东西

记住!我的名字叫@{name}

我不想把判断放在tpl里面,因为如果name用的地方多,则需要写很多个if。

请问这个如果用封装好的方法有办法解决吗

from juicer.

PaulGuo avatar PaulGuo commented on July 26, 2024

可以借助 juicer 的自定义 helper 函数解决之。

比如模板这么写: ${data.sex | name}

// 定义 helper
juicer.register('name', function(sex) {
    if(sex=='man'){
        return "张三";
    }else{
        return "李四"
    }
});
// 渲染,输出张三
juicer('${data.sex | name}', {data: {sex: 'man'}});

from juicer.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.