lightncandy
lightncandy copied to clipboard
Too many nested {{else if}} causes compile error
The Handlebars Code:
This doesn't work:
{{#if conditionA }}
{{#if conditionA1 }}
// Do something then do more stuff conditionally
{{#if conditionA1.1 }}
// Do something here
{{else if conditionA1.2 }}
// Do something else here
{{else if conditionA1.3 }}
// Do something else here
{{/if}}
{{else}}
// Do something else
{{/if}}
{{else if conditionB }}
// Do something else
{{#if conditionB1 }}
// Do something conditionally
{{/if}}
{{#if conditionB2 }}
// Do another thing conditionally
{{/if}}
{{else if conditionC }}
// Do something else
{{else}}
// Finally, do this last thing if all else fails
{{/if}}
But this works:
{{#if conditionA }}
{{#if conditionA1 }}
// Do something then do more stuff conditionally
{{#if conditionA1.1 }}
// Do something here
{{else}}
{{#if conditionA1.2 }}
// Do something else here
{{else}}
{{#if conditionA1.3 }}
// Do something else here
{{/if}}
{{/if}}
{{/if}}
{{else}}
// Do something else
{{/if}}
{{else if conditionB }}
// Do something else
{{#if conditionB1 }}
// Do something conditionally
{{/if}}
{{#if conditionB2 }}
// Do another thing conditionally
{{/if}}
{{else if conditionC }}
// Do something else
{{else}}
// Finally, do this last thing if all else fails
{{/if}}
The Issue:
I keep running into a compilation error that seems to be caused by too many nested {{else if}}
statements. The error that gets thrown says a previous {{else if}}
is unclosed when in fact it's followed by another {{else if}}
or {{else}}
. I've confirmed that I do not run into the same error if using nested {{#if}}...{{else}}...{{/if}}
expressions.
I'm still running into issues that I believe are stemming back to this problem. More recently, I've encountered errors that state that there is an unclosed {{#if}}
block when, in fact, the said {{#if}}
block has multiple {{else if}}
, with up to 3 levels of nested if/else if/else
blocks, followed by an {{else}}
and finally a closing {{/if}}
tag.
When you compile the template with flag LightnCandy::FLAG_HANDLEBARS | LightnCandy::FLAG_ERROR_EXCEPTION
, the template receives Exception: No argument after {{#if}} !
, it means "We do not allow {{#if}}
but only allow {{#if something}}
". (You can not check the condition without the condition expression)
In the mean time, the provided template can not be compiled by handlebars.js, neither. Please fix the template first.
Close this. Feel free to reopen this if you find any related issue, thanks.
When you compile the template with flag
LightnCandy::FLAG_HANDLEBARS | LightnCandy::FLAG_ERROR_EXCEPTION
, the template receivesException: No argument after {{#if}} !
, it means "We do not allow{{#if}}
but only allow{{#if something}}
". (You can not check the condition without the condition expression)In the mean time, the provided template can not be compiled by handlebars.js, neither. Please fix the template first.
@zordius, thanks for your reply as it helped me notice that the code snippet in my original post did contain some unintended typos as a byproduct of trying to replicate a simplified version of my actual use case. These typos were not consistent with my actual code, so I updated the code snippet that I shared with you above to remove the extraneous {{#if}}
, replacing it what should've been an {{/if}}
. As you mentioned, the typos would've yielded a different error entirely than the ones I've been regularly receiving on a rather consistent basis while trying to integrate LightnCandy into a project.