Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can you refer to variables with dashes in jade?

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']}")
like image 256
ZECTBynmo Avatar asked Sep 30 '22 07:09

ZECTBynmo


1 Answers

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.

like image 103
p.s.w.g Avatar answered Oct 05 '22 07:10

p.s.w.g