Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Too many nested {{else if}} causes compile error #313

Open
laurenhamel opened this issue Jun 21, 2019 · 4 comments
Open

Too many nested {{else if}} causes compile error #313

laurenhamel opened this issue Jun 21, 2019 · 4 comments
Assignees
Labels
Milestone

Comments

@laurenhamel
Copy link

laurenhamel commented Jun 21, 2019

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.

@laurenhamel
Copy link
Author

laurenhamel commented Jul 9, 2019

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.

@zordius
Copy link
Owner

zordius commented Jul 27, 2019

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.

@zordius
Copy link
Owner

zordius commented Jul 28, 2019

Close this. Feel free to reopen this if you find any related issue, thanks.

@zordius zordius closed this as completed Jul 28, 2019
@laurenhamel
Copy link
Author

laurenhamel commented Jul 30, 2019

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.

@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.

@zordius zordius reopened this Aug 2, 2019
@zordius zordius added bug and removed invalid labels Aug 2, 2019
@zordius zordius self-assigned this Aug 2, 2019
@zordius zordius added this to the 1.2.5 milestone Aug 2, 2019
@zordius zordius modified the milestones: 1.2.5, 1.2.6 Mar 8, 2020
@zordius zordius modified the milestones: 1.2.6, 1.2.7 Jul 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants