-
Notifications
You must be signed in to change notification settings - Fork 11
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
Add shorthand include support #5
Comments
Thanks for suggesting this, however I'm not so sure this would be a valuable improvement as is. First of all, including files from different directories is not a big deal. You can easily add I want to avoid changes that would make Crinja templates incompatible to the original Jinja2 template language. I think it has great value for both to be compatible (at least as good as possible), so people who already know Jinja don't need to learn different semantics and templates can be easily reused. I wouldn't dogmatically exclude any changes diverging from Jinja, but if one is to be accepted, it should come with a very reasonable benefit. The feature you're describing with just plain template names is similar to how Liquid handles includes. The way this works in Jinja and Crinja is however more logical and powerful: The include tag receives an argument with the name of the template to include. From a language design perspective, this name should be a string. If applied directly, this should be expressed a string literal, not a keyword. Additionally, this behaviour allows to pass in any expression as include name.
That being said, there is actually an experimental config setting |
Thanks for the thorough reply. I don't quite understand how I tried using a variable |
The default include path is This loader, for example will first try to resolve the include name in crinja.loader = FileSystemLoader.new([".", "./includes"]) |
Thanks! I got it to work, but when I use this method HTML tags like |
What do you mean with old behaviour? Crinja has To disable autoescape entirely, set |
Thanks. I use the output from markd as input to Crinja. It's weird that the variables weren't escaped before, though. I did some testing and found out that HTML is only escaped with require "crinja"
data = {"world" => "<span>world</span>!"}
puts Crinja::Template.new("Hello {{ world }}").render(data)
# => "Hello <span>world</span>!"
crinja = Crinja.new
crinja.loader = Crinja::Loader::FileSystemLoader.new([".", "./includes"])
puts crinja.from_string("Hello {{ world }}").render(data)
# => "Hello <span>world</span>!"
puts crinja.get_template("test.html").render(data)
# => "Hello <span>world</span>!"
|
Oh, my bad. It's If you parse a template directly from a string, Crinja can't know it is intended to be HTML content. Therefore it won't automatically enable |
Thanks, that makes sense. Everything is working now, thanks for the help! |
You're welcome. I'll try to improve the documentation on these things based on this issue. |
Usually when working with static site generators, there are two common directories: one for includes and one for the layouts that use these includes. Example:
Since this type of pattern is so common, I propose the following shorthand:
How does it work? If no explicit path is given (i.e. no quotation marks), look inside the default includes directory (customizable by the user), then:
Crinja::TemplateNotFoundError
like usual.The text was updated successfully, but these errors were encountered: