Can you refer to variables with dashes in jade?

妖精的绣舞 提交于 2019-12-23 15:12:59

问题


I'm trying to do something like this in my jade template

a.apply-url(href="#{apply-url}")

But it's being interpreted as 'apply minus url'

Is there a way I can force the interpreter to do the right thing? Or is there some way to refer to a top-level object, and put the index in quotes, like this?

a.apply-url(href="#{this['apply-url']}")

回答1:


I'm not all that familiar with Jade, but I have looked into it a little bit before. After playing around a while here, I was able to get this to work:

a.apply-url(href="#{locals['apply-url']}")
{"apply-url": "foo"}

produces:

<a href="foo" class="apply-url"></a>

This works because this particular implementation stores the data in a local variable named locals which is then closed over by the templating function. As far as I can tell, this is an implementation detail, and I wouldn't necessarily expect this to work in other Jade implementations.



来源:https://stackoverflow.com/questions/24855111/can-you-refer-to-variables-with-dashes-in-jade

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!