Answer the question
In order to leave comments, you need to log in
Logical check does not work correctly in Handlebars, how to fix it?
Good day!
the code of the template and two express routes on jsfiddle.net
I pass an object in the routes, through res.render, I pass the string as the last property. In each route, as you noticed, a different string value. In the Handlebars template, I check these lines in the {{# unlessEq page 'home' }} - page !== 'home' and {{# eq page 'artistList'}} - page === 'artistList' helpers.
This check is in {{#each artists}}. Outside {{#each artists}} the check works as it should, inside {{#each artists}} it always passes true on the first check and false on the second check (what is the reason is not clear), regardless of which route I went to. {{#each artists}} does not react in any way to the post property which is not in the array of artists objects, when in {{#each artists}} I just try to display {{post}} it does not display anything, neither on the page in the browser nor in there are no errors in the console and in general {{post}} does not manifest itself in any way.
I tried to write differently for the sake of experiment, to see what would happen, and so I wrote {{#unlessEq @page 'home' }} and so {{#unlessEq $page 'home' }} does not react, and when I write like this {{# unlessEq (page 'artistList)'}} in the browser prints that there is no page helper -- Missing helper: "page", and like this {{#unlessEq {{page}} 'home' }} in the browser prints -- Parse error on line 18:
The question is how to insert a post into the check so that it works correctly? Again, outside of each everything works as it should.
Or maybe Handlebars doesn’t know how to do this at all, but I’m torturing him) and here you need your own crutch))
Answer the question
In order to leave comments, you need to log in
it's obvious that the page inside your each isn't defined, which is why it doesn't work as it should.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question