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 you bring back the documentation on extends and includes? #47

Open
sam-hoffman opened this issue Feb 1, 2022 · 4 comments
Open
Labels
doc Related to documentation

Comments

@sam-hoffman
Copy link

I found some deleted documentation on extends and includes in the git history - https://github.com/pwwang/liquidpy/blob/bbe9cf672eca96e3d44715a16ae31dab377dab19/docs/extends_include.md

It was helpful! Could it be undeleted, please?

@pwwang
Copy link
Owner

pwwang commented Feb 2, 2022

That documentation was for the code before refactoring.
Now liquidpy is using extends/include from jinja2 itself. You can find documentation for them below:

https://jinja.palletsprojects.com/en/3.0.x/templates/#include
https://jinja.palletsprojects.com/en/3.0.x/templates/#template-inheritance

@sam-hoffman
Copy link
Author

ok, thanks! would it be possible to mention in the main documentation that this is how extends and includes works now? It was a little hard to figure out

@pwwang pwwang added the doc Related to documentation label Feb 2, 2022
@lovering810
Copy link

Specific include Example

Adding on to this: the docs on compatibility explicitly say that with Jekyll,

passing variables to a sub-template using include tag is not supported

implying that it is supported in other modes. Is it? (I've also looked into doing what the Jekyll recommendation states, which is using Jinja2's with statement, but sadly, that is now deprecated, which is probably a docs update of its own.)

The following throws a TemplateSyntaxError: expected token 'end of statement block', got 'code'

"system":{% include 'ValueSet/SystemReference' code: Identifier.root %}

What is the expected behavior? Should include in wild mode correctly retrieve the template and apply the locally-set variable? Is there another way to do this that I'm missing? I've spent some time in the Shopify, Jinja, and liquidpy docs, but am not sure which governs this behavior, as they are all in kind of different places about it (Shopify deprecated include, Jinja2 deprecated with - "Changed in version 2.9: This extension is now built-in and no longer does anything.", and liquidpy docs don't talk about this functionality in particular).

pwwang added a commit that referenced this issue Feb 16, 2022
@pwwang
Copy link
Owner

pwwang commented Feb 16, 2022

Thanks for pointing this out.

Passing variables via include is not supported in any mode. I was mentioning this in the doc is because, amongst those variants of liquid, jekyll is the only one that supports the include tag.

However, you are correct that with is deprecated by jinja, by default, the sub-template by include has access to the variables where it's included. So the default behavior is:

{% include 'ValueSet/SystemReference' with context %}

See https://jinja.palletsprojects.com/en/3.0.x/templates/#include

If you want code to be accessed inside your template ValueSet/SystemReference:

{% assign code = Identifier.root %}
{% include 'ValueSet/SystemReference' %}

But the best practice is that, if you want flexibility in your sub-template, you should use macros combined with import.

See this answer: https://stackoverflow.com/a/9405157/5088165

See also tests that I added regarding this issue:
https://github.com/pwwang/liquidpy/blob/dev/tests/wild/test_include.py

@pwwang pwwang mentioned this issue May 3, 2022
pwwang added a commit that referenced this issue May 3, 2022
* ✅ Add tests regarding #47

* 📌 Upgrade and pin dependencies

* ➕ Add toml as dep needed by python-frontmatter

* 🔖 0.7.4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
doc Related to documentation
Projects
None yet
Development

No branches or pull requests

3 participants