How can I render the values of two variables {{item_link}}
and {{item_value}}
inside the same div class?
I am using the #if
helper to conditionally render the block. If I render them separately I am able to evaluate them, but if I try doing something like {{#if item_link && item_value}}
, so I can then use them inside the div, it does not work. These are Handlebars layout templates. Is there a way to do it? Thanks!
2
Answers
Here is a solution I found. I moved the AND logic inside my js file and created a single object
object = {item_link_name: item_link_value, item_value_name: item_value_value}
. This way I can effectively html render with{{object}}
or with{{#if object}} ... {{/if}}
(if I need also to have some additional logic in my html, modulo the one included in my js) and refer to the individual values with{{item_link_value}}
and{{item_value_value}}
.You can render the values inside the same div by concatenating them using the {{concat}} helper: