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

Block Assignment Filters #486

Closed
eli-collins opened this issue Sep 5, 2015 · 3 comments
Closed

Block Assignment Filters #486

eli-collins opened this issue Sep 5, 2015 · 3 comments

Comments

@eli-collins
Copy link

2.8's block assignments have been incredibly useful, but I've found myself doing the following a lot...

{% set title %}
    <h1>{{ value }}</h1>
{% endset %}
{% set title = title | safe %}

Would it be possible to allow moving the filter call into the block assignment call, such as with the following syntax?

{% set title | safe %}
    <h1>{{ value }}</h1>
{% endset %}

(There might be a better / more generally flexible syntax, that's just the one that first occurred to me to try).

@ThiefMaster
Copy link
Member

👍

You could use {% filter safe %}...{% endfilter %} inside the set block though. But of course it's not as pretty.

ThiefMaster added a commit to ThiefMaster/jinja that referenced this issue Sep 11, 2015
- e.g {% set foo | trim %}...{% endset %}
- closes pallets#486
ThiefMaster added a commit to ThiefMaster/jinja that referenced this issue Sep 11, 2015
- e.g {% set foo | trim %}...{% endset %}
- closes pallets#486
ThiefMaster added a commit to ThiefMaster/jinja that referenced this issue Sep 11, 2015
- e.g {% set foo | trim %}...{% endset %}
- closes pallets#486
@ThiefMaster
Copy link
Member

Actually, the fact that you need to filter your set block as safe feels more like a bug to me since it results in double-escaped data very easily (which is something Jinja is usually pretty good at avoiding!).

Opened another issue about this: #490

@eli-collins
Copy link
Author

#490 alone would definitely solve all my use-cases; if that was pushed through, I'd be happy whichever way you end up deciding this issue. Without the frequent need to use a 'safe' filter, the block filter syntax is probably more than sufficient for the remaining edge cases that I can think of.

ThiefMaster added a commit to ThiefMaster/jinja that referenced this issue Jan 6, 2017
- e.g {% set foo | trim %}...{% endset %}
- closes pallets#486
ThiefMaster added a commit to ThiefMaster/jinja that referenced this issue Jan 7, 2017
- e.g {% set foo | trim %}...{% endset %}
- closes pallets#486
ThiefMaster added a commit to ThiefMaster/jinja that referenced this issue Jan 7, 2017
- e.g {% set foo | trim %}...{% endset %}
- closes pallets#486
ThiefMaster added a commit to ThiefMaster/jinja that referenced this issue Jan 7, 2017
- e.g {% set foo | trim %}...{% endset %}
- closes pallets#486
ThiefMaster added a commit to ThiefMaster/jinja that referenced this issue Jan 7, 2017
- e.g {% set foo | trim %}...{% endset %}
- closes pallets#486
ThiefMaster added a commit to ThiefMaster/jinja that referenced this issue Jan 9, 2017
- e.g {% set foo | trim %}...{% endset %}
- closes pallets#486
ThiefMaster added a commit to ThiefMaster/jinja that referenced this issue Apr 5, 2017
- e.g {% set foo | trim %}...{% endset %}
- closes pallets#486
ThiefMaster added a commit to ThiefMaster/jinja that referenced this issue Jun 24, 2017
- e.g {% set foo | trim %}...{% endset %}
- closes pallets#486
ThiefMaster added a commit to ThiefMaster/jinja that referenced this issue Aug 22, 2017
- e.g {% set foo | trim %}...{% endset %}
- closes pallets#486
ThiefMaster added a commit to ThiefMaster/jinja that referenced this issue Aug 22, 2017
- e.g {% set foo | trim %}...{% endset %}
- closes pallets#486
ThiefMaster added a commit to ThiefMaster/jinja that referenced this issue Oct 31, 2017
- e.g {% set foo | trim %}...{% endset %}
- closes pallets#486
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants