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

Is it possible to apply a filter to the output of a tag? #234

Open
unitof opened this issue Jun 16, 2020 · 2 comments
Open

Is it possible to apply a filter to the output of a tag? #234

unitof opened this issue Jun 16, 2020 · 2 comments

Comments

@unitof
Copy link

unitof commented Jun 16, 2020

I have a custom tr tag that returns internationalized strings from a dictionary, and I'd like to apply a Selmer filter to its output. Is that possible?

As a simple example: say {% tr core/greeting %} parses to Hello or Hola depending on a user's current language preference, and I'd like to then apply |upper to the output of that tag.

@yogthos
Copy link
Owner

yogthos commented Jun 16, 2020

There isn't a way to do that currently, but you can access the filters in the tag implementation, e.g: (:upper @selmer.filters/filters).

@boxxxie
Copy link
Contributor

boxxxie commented Jul 7, 2022

@unitof a tag is expected to output a rendered template, while a filter is an operation on a variable.
what you could do is create a filter tag, which you could wrap a tag in, which would apply an existing filter to the contents in a tag. this doesn't make sense for a lot of filters.

{% filter uppercase %}
    {% tr core/greeting %}
{% endfilter %}

another option is to add a filter as a tag param

{% tr core/greeting filters=uppercase|replace:whatever %} something like that. and how far you go with parsing would be up to you.

i think a param is probably better than a wrapper tag. i haven't run into needing to apply filters to tags, and i do a lot of weird stuff with templating. i think i would likely approach your tr tag solution as a filter itself, but that's a person preference.

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

No branches or pull requests

3 participants