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

Allow block definitions in if/for/match blocks (fixes #335) #336

Merged
merged 2 commits into from
Jun 3, 2020
Merged

Conversation

djc
Copy link
Owner

@djc djc commented Jun 2, 2020

No description provided.

@djc
Copy link
Owner Author

djc commented Jun 2, 2020

@jmafc do you want to try this out?

@jmafc
Copy link

jmafc commented Jun 2, 2020

Do I just have to reference the master branch in my Cargo.toml to do that?

@djc
Copy link
Owner Author

djc commented Jun 2, 2020

Well, the deep-blocks branch for now, but yes, that should do it.

@jmafc
Copy link

jmafc commented Jun 2, 2020

Ok, I tried it, but it still causes the message: blocks ('meta_descrip') are only allowed at the top level of a template or another block. The meta_descrip is the what meta_x stood for in previous examples, and as shown in the example, the block is nested within an {% else %}. I'm pretty I got your code because the Cargo.lock shows source = "git+https://github.com/djc/askama?branch=deep-blocks#79374b96812dc8454b28bccd05757d90e87b104f" which is your commit.
Also, in order to test I had to disable a call to a macro, because it was causing message: unable to parse template. The macro was parsing and processing OK when building with askama 0.8.0. The macro has a for loop to output HTML list items and includes an if !loop.last block.
Let me know if you need further details.

@djc
Copy link
Owner Author

djc commented Jun 3, 2020

Ah yes, I forgot to strip out the code in the code generator that panics if it encounters a nested block definition. That's fixed with the latest push.

Can you file a separate issue about the macro thing? That seems unrelated, and potentially a regression. Would like have a minimal reproduction of the template syntax for that.

@jmafc
Copy link

jmafc commented Jun 3, 2020

Ok, the blocks ('meta_descrip') are only allowed at the top level of a template or another block is no longer reported. I'll file the issue about the macro regression later today.

@djc
Copy link
Owner Author

djc commented Jun 3, 2020

And does the template with the if-nested block produce the expected output? :)

@jmafc
Copy link

jmafc commented Jun 3, 2020

Yes it did produce the expected output (eventually, because one of my templates had an unrecognized field, but I've fixed that now).

@djc djc merged commit 7da4ad5 into master Jun 3, 2020
@delete-merged-branch delete-merged-branch bot deleted the deep-blocks branch June 3, 2020 18:56
@djc
Copy link
Owner Author

djc commented Jun 3, 2020

Cool, thanks for checking.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants