I m using jade's dot syntax to render the HTML. Inside that template I used some code to iterate some data ( posts ). But cannot get the output, it gives an error as :
Cannot read property 'title' of undefined
I know i m using the incorrect syntax to use codes inside the dot syntax method. But don't know how to correct it. The following is the code. Please note:
div.container.
<div class="test">
each post, i in posts
<div class="cls">#{post.title}</div>
</div>
Any help is more appreciable.
Jade doesn't allow for using most of its syntax, such as each
iteration, where plain text is expected, such as inside "Block Text" tags (dot-suffixed).
Currently, the each post, ...
is being output as text content rather than being evaluated, so it isn't defining post
(and i
) for #{post.title}
to succeed.
You could instead use lines of "Piped Text" to mix the HTML and jade's each
iteration.
div.container
| <div class="test">
each post, i in posts
| <div class="cls">#{post.title}</div>
| </div>
Or, you can also use Jade's own syntax throughout:
div.container
.test
each post, i in posts
.cls= post.title