Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

关于<%%>内的注释问题 怎么写 #15

Closed
pulo opened this issue Sep 28, 2012 · 3 comments
Closed

关于<%%>内的注释问题 怎么写 #15

pulo opened this issue Sep 28, 2012 · 3 comments

Comments

@pulo
Copy link

pulo commented Sep 28, 2012

<%%>里可以写JS,但是有注释就出错了
双斜杠好像不行

另外请问下 <%%>里如何读取传进去的数据呢

@PaulGuo
Copy link
Owner

PaulGuo commented Sep 28, 2012

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

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

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

@PaulGuo PaulGuo closed this as completed Sep 28, 2012
@pulo
Copy link
Author

pulo commented Sep 29, 2012

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

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

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

我的名字叫@{name}

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

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

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

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

@PaulGuo
Copy link
Owner

PaulGuo commented Sep 29, 2012

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

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

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants