Question

When doing this:

div(id=player)
  ul.timeline
    {{#epochs}}
    li.epoch {{epoch}}
    {{/epochs}}

and render it with hogan

html = ss.tmpl['board'].render({ //ss is for socketstream, it uses hogan.
  epochs: treeStructure,
  player: "player2"
});

I get the following error

! Errror formatting Jade template
/Users/ilyadorman/dev/game/client/templates/board.jade:2
    1| div(id=player)
  > 2|   ul.timeline
    3|     {{#epochs}}
    4|     li.epoch {{epoch}}
    5|     {{/epochs}}

player is not defined

But when I do {{player}} it works fine! What am I missing?

Was it helpful?

Solution

Like it says, player is not defined within the context you are trying to use it in.

You could put single or double quotes around player and then it would be defined-- as a primitive string.

Like div(id='player').

If that's what you want. If you want the div's id to be dynamically altered with the variable then you should use the double curlies for that to be passed in.

These are different programmatic contexts. You can define variables within a Jade template and perform operations on them, but these are different from the variables passed in, which in Hogan/Mustache are called tags. In this case, you want the tags.

I've never tried anything like this, but something along the lines of

div(id='{{player}}')

should work.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top