Can you refer to variables with dashes in jade?

ZECTBynmo

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']}")
p.s.w.g

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.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Why can't environment variables with dashes be accessed in bash 4.1.2?

From Dev

Can you refer to a var using a string in PHP?

From Dev

Why can you not refer to a variable when shadowing it?

From Dev

In Jade, how can you call a function in an external Javascript

From Dev

In Jade, how can you call a function in an external Javascript

From Dev

Can you add variables into a dictionary

From Dev

Jade Variables for Links

From Dev

pass variables to jade template

From Dev

With a mongoose .update query, can you refer to the fetched record in the update parameter?

From Dev

Can you have types that refer to each other in Julia?

From Dev

Can I refer to variables created earlier in a MySQL select statement?

From Dev

Can you build a URL in Restangular with multiple variables?

From Dev

Can you use Jekyll layout variables in pages?

From Dev

Can you declare multiple variables at once in Go?

From Dev

Can you access private variables using OGNL?

From Dev

Can you use variables to specify field width?

From Dev

Can you use environmental variables in qt creator?

From Dev

Can you access subclass variables with object of superclass?

From Dev

Can you declare multiple with variables in a django template?

From Dev

can you put variables in with writing? See for details

From Dev

Can you use variables inside $'...' in bash?

From Dev

Refer to other jade file in Node JS

From Dev

Can I use a Jade if conditional to change a style class value? Using flash variables

From Dev

php json decode with variables that contains dashes

From Dev

php json decode with variables that contains dashes

From Dev

Jade - print all possible variables

From Dev

Passing variables through Jade templates

From Dev

Print variables inside jade file

From Dev

Print variables inside jade file

Related Related

  1. 1

    Why can't environment variables with dashes be accessed in bash 4.1.2?

  2. 2

    Can you refer to a var using a string in PHP?

  3. 3

    Why can you not refer to a variable when shadowing it?

  4. 4

    In Jade, how can you call a function in an external Javascript

  5. 5

    In Jade, how can you call a function in an external Javascript

  6. 6

    Can you add variables into a dictionary

  7. 7

    Jade Variables for Links

  8. 8

    pass variables to jade template

  9. 9

    With a mongoose .update query, can you refer to the fetched record in the update parameter?

  10. 10

    Can you have types that refer to each other in Julia?

  11. 11

    Can I refer to variables created earlier in a MySQL select statement?

  12. 12

    Can you build a URL in Restangular with multiple variables?

  13. 13

    Can you use Jekyll layout variables in pages?

  14. 14

    Can you declare multiple variables at once in Go?

  15. 15

    Can you access private variables using OGNL?

  16. 16

    Can you use variables to specify field width?

  17. 17

    Can you use environmental variables in qt creator?

  18. 18

    Can you access subclass variables with object of superclass?

  19. 19

    Can you declare multiple with variables in a django template?

  20. 20

    can you put variables in with writing? See for details

  21. 21

    Can you use variables inside $'...' in bash?

  22. 22

    Refer to other jade file in Node JS

  23. 23

    Can I use a Jade if conditional to change a style class value? Using flash variables

  24. 24

    php json decode with variables that contains dashes

  25. 25

    php json decode with variables that contains dashes

  26. 26

    Jade - print all possible variables

  27. 27

    Passing variables through Jade templates

  28. 28

    Print variables inside jade file

  29. 29

    Print variables inside jade file

HotTag

Archive