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

Question: any way to use custom filters? #70

Closed
mirceaulinic opened this issue Feb 26, 2017 · 6 comments
Closed

Question: any way to use custom filters? #70

mirceaulinic opened this issue Feb 26, 2017 · 6 comments

Comments

@mirceaulinic
Copy link

Hello,

Thank you for opensourcing this project!
I'm very new to this library and the first question I have in mind (you may find it trivial): is there any flexible way to extend the list of existing filters?

More specifically, I am thinking about a way to inject external logic. If comfortable with the context, something similar to the Jinja filters.
Is this currently possible or on the roadmap?

Thanks,
Mircea

@awbraunstein
Copy link
Contributor

I believe this is already supported.

If you want to filter something using a custom filter, you can use it like so:

${some_variable|filter=my_custom_filter}

Where my_custom_filter is some function that is currently in scope. For example, the simplest filter is str, which should essentially be a passthrough.

Your template may look something like this:

#from my.awesome.package import my_awesome_filter

#def main
  #set $foo = "my awesome value"
  ${foo|filter=my_awesome_filter}
#end def

@mirceaulinic
Copy link
Author

Hi @awbraunstein - thanks for clarifying this!

Please excuse my ignorance, but I didn't find the documentation. Do you have any wiki page or so, having the answer to questions as I had above?

@awbraunstein
Copy link
Contributor

Documentation isn't great, but you can see this syntax referenced here: https://github.com/youtube/spitfire/blob/master/doc/SpitfireVsCheetah.md#placeholders-and-filters-should-be-easier-to-use-in-the-end

Additionally, there are tests that use this syntax too. https://github.com/youtube/spitfire/blob/master/tests/filter_placeholder_2.tmpl#L10

I think that better documentation is something that this project needs. I'll open an issue to track this.

@mirceaulinic
Copy link
Author

Cheers @awbraunstein - may I suggest adding a dedicated wiki? It's a pretty good Github feature to manage docs.
I will also contribute later when I'll have more experience with spitfire.

@awbraunstein
Copy link
Contributor

Yes. I think a wiki is the route we will go for documentation. Thanks for the suggestion.

@awbraunstein
Copy link
Contributor

If you're interested, you can follow the documentation issue here: #71

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

No branches or pull requests

2 participants