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 referring to root context with . #24

Open
rossmacarthur opened this issue Feb 23, 2024 · 3 comments
Open

Allow referring to root context with . #24

rossmacarthur opened this issue Feb 23, 2024 · 3 comments
Labels
feature New feature or request

Comments

@rossmacarthur
Copy link
Owner

This could be useful if the root context is not a map, see #22.

There are some questions here though because the root context is not a single map but rather multiple scopes containing values. This would require copying the entire context which could potentially be expensive.

@rossmacarthur rossmacarthur added the feature New feature or request label Feb 23, 2024
@qq253498229
Copy link

qq253498229 commented Aug 23, 2024

Has this feature been released? @rossmacarthur
How should I use the variables passed from the parent template?

parent:

{% include "text-format" with node.children %}

child:

{% for child in . %}
{% if child.category.type | eq: "Text" %}
{{ child.category.text }}
{% endif %}
{% endfor %}

error:

invalid syntax

  --> text-format:1:17
   |
 1 | {% for child in . %}
   |                 ^--
   |
   = reason: expected expression, found member access operator

@rossmacarthur
Copy link
Owner Author

rossmacarthur commented Aug 24, 2024

It hasn't been implemented. You will have to pass node to the sub template right now.

{% include "text-format" with node %}
{% for child in children %}
{% if child.category.type | eq: "Text" %}
{{ child.category.text }}
{% endif %}
{% endfor %}

@rossmacarthur
Copy link
Owner Author

rossmacarthur commented Dec 5, 2024

I put some thought into it, there are some outstanding questions:

  • What is the expected behaviour with multiple scopes of values, does it always refer to the root context or all of the contexts merged?
{% for k, v in object %}
    {% with k | transform as name %}
        {{ . }} <!-- does this have k, v, name, loop merged into the global context? -->
    {% endwith %}
{% endfor %}
  • What is the expected behaviour when using render_from_fn? The options:
    a) passing . directly to the render fn (empty path)
    b) just returning any locally scoped variables (see above)
    c) some combination of these?

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

No branches or pull requests

2 participants