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

fails on html tags using if/else #95

Open
josharian opened this issue Oct 13, 2022 · 2 comments
Open

fails on html tags using if/else #95

josharian opened this issue Oct 13, 2022 · 2 comments
Labels
bug Something isn't working

Comments

@josharian
Copy link

We have code structurally similar to this (only more complex, with different tags):

{{ if .B }}
  <span>
{{ else }}
  <div>
{{ end }}

something

{{ if .B }}
  </span>
{{ else }}
  </div>
{{ end }}

This yields:

Error: An error occured during printing. Found invalid node block.

This is similar to #59, but it causes an error instead of duplication.

@josharian
Copy link
Author

This obviously can't be solved in the general case. (The if statement could call a Go function, so solving this is equivalent to solving the halting problem.) But some common cases could be special-cased to handle most scenarios.

@NiklasPor NiklasPor added the bug Something isn't working label Oct 14, 2022
Repository owner deleted a comment Oct 19, 2022
@maxrzaw
Copy link

maxrzaw commented Nov 5, 2023

While not exactly the same. This seems like a similar scenario that can be handled correctly every time because the same tag is used in both the if and the else block:

{{ define "test" }}
  {{ if .Active }}
  <li class="active">
  {{ else }}
  <li class="inactive">
  {{ end }}
  </li>
{{ end }}

[error] test.html: Error: An error occured during printing. Found invalid node root.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants