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

Shorthand for filter tag #244

Open
ilyapuchka opened this issue Sep 22, 2018 · 3 comments · May be fixed by #257
Open

Shorthand for filter tag #244

ilyapuchka opened this issue Sep 22, 2018 · 3 comments · May be fixed by #257

Comments

@ilyapuchka
Copy link
Collaborator

ilyapuchka commented Sep 22, 2018

I found myself using filter indent quite often in one of the templates and it would be nice to be able to use

{% indent:4," ",true %}...{% endindent %}

instead of

{% filter indent:4," ",true %}...{% endfilter %}

This will not just make it shorter but will provide more context in the closing tag.

@yonaskolb
Copy link
Collaborator

Where do you usually use these indents? Around include blocks or in other places as well?

I only use them around include so would love to have a way of easily indenting the contents of those

@ilyapuchka
Copy link
Collaborator Author

ilyapuchka commented Sep 23, 2018

@yonaskolb I'm not using includes in this particular template as it is relatively short (it generates implementations for test cases) and use it to indent sections of generated code with several levels of indentations so there are quite a few indent filters.

For include node we can add support for applying filter to its content so that it will be similar to what filter node does. Like this:

{% include "some.stencil" | indent:4, " ",true %}

It's unfortunate that we don't separate context variable and template name with any keyword, like {% include "some.stencil" with value %}, if we were we would be able to apply filters to both variable and included template with a better syntax, i.e.

{% include "some.stencil" | uppercase with value | lowercase %}

instead of what we can have now:

{% include "some.stencil" | uppercase value | lowercase %}

But let's discuss that in another issue?

@ilyapuchka ilyapuchka linked a pull request Sep 30, 2018 that will close this issue
@ilyapuchka
Copy link
Collaborator Author

For include tag we will need to add brackets parsing so that we can parse this {% include template|lowercase %} and {% include (template|lowercase) | uppercase %} correctly (first only applies filter on template name variable, second applies lowercase filter on template name variable and uppercase filter on template content).
It can probably work the same way with sub context, i.e {% include (template|lowercase child|mapValues:lowercase) | uppercase %}

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

Successfully merging a pull request may close this issue.

2 participants