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

Can't include a file that has macro definitions in it #40

Closed
Eijebong opened this issue Aug 25, 2017 · 4 comments
Closed

Can't include a file that has macro definitions in it #40

Eijebong opened this issue Aug 25, 2017 · 4 comments

Comments

@Eijebong
Copy link
Contributor

Hey,

It would be great to be able to have macros in a file and be able to include that file in another.
Currently it's hitting panic!("no extends or macros allowed in content");.

@djc
Copy link
Owner

djc commented Aug 25, 2017

Not sure how you're trying to put to your macro definitions to get that error, but that error will remain in there even if you can import macro definitions from another file. It indicates that you're trying to define a macro somewhere not at the top-level of a template file, is that what you're doing?

Macro imports are definitely on the list, just lower priority than escaping by default right now.

@Eijebong
Copy link
Contributor Author

Yeah I have a macros.html file with macros definitions in it and am including it in another template.

Do you think there is a better way to fix that than changing how include currently works and parse the included file at the beginning and include its nodes in the current template nodes ? (parse it here and append nodes to the current nodes somehow) https://github.com/djc/askama/blob/master/askama_derive/src/generator.rs#L17

@djc
Copy link
Owner

djc commented Aug 26, 2017

Jinja very clearly separates include and import, as far as I can tell, where include basically renders the included file into the including template while import makes the macros from the imported template available to the importing template. So your use case seems to need an import mechanism. In terms of implementation, it could perhaps function similarly to the handling for defmacro, in the sense that top-level import blocks are removed from the AST and instead result in having some macros added to the macro map.

@djc
Copy link
Owner

djc commented Oct 15, 2017

Thanks to @larros for fixing this!

@djc djc closed this as completed Oct 15, 2017
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

No branches or pull requests

2 participants