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

added ability to add custom filters #211

Merged
merged 1 commit into from
Jul 10, 2018
Merged

Conversation

josephmancuso
Copy link
Member

This PR adds the ability to add custom filters.

All we need to do is use the filter method on the view class:

def slug(item):
    return item.replace(' ', '-')

ViewClass.filter('slug', slug)

and then inside the template:

{{ app.name|slug }}

The real world example would be to just throw this inside a provider:

class UserModelProvider(ServiceProvider):
    ''' Binds the User model into the Service Container '''

    wsgi = False

    ...

    def boot(self, Request, ViewClass):
        ViewClass.filter('slug', self.slug)

    @staticmethod
    def slug(item):
        return item.replace(' ', '-')

and boom. You now have a filter inside all of your templates.

@josephmancuso josephmancuso added enhancement New feature or request next minor Issue scheduled for the next minor release labels Jul 9, 2018
@josephmancuso josephmancuso self-assigned this Jul 9, 2018
@coveralls
Copy link

coveralls commented Jul 9, 2018

Coverage Status

Coverage increased (+0.02%) to 91.295% when pulling 76aae09 on add-jinja2-filters into b259858 on master.

@aisola aisola self-requested a review July 9, 2018 21:02
Copy link
Contributor

@aisola aisola left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me!

@josephmancuso josephmancuso merged commit 4d7663a into master Jul 10, 2018
@josephmancuso josephmancuso deleted the add-jinja2-filters branch July 11, 2018 12:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request next minor Issue scheduled for the next minor release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants