Skip to content

Instantly share code, notes, and snippets.

@gazpachoking
Created March 6, 2012 20:41
Show Gist options
  • Select an option

  • Save gazpachoking/1988861 to your computer and use it in GitHub Desktop.

Select an option

Save gazpachoking/1988861 to your computer and use it in GitHub Desktop.
FlexGet plugin which adds custom jinja filters
"""
This plugin just registers more functions as jinja filters. You can then use the filters from any
jinja template in FlexGet like normal. e.g. {{afield|myfilter}}
"""
import logging
log = logging.getLogger('my_filters')
def filter_myfilter(val):
return 'blah'
@event('manager.startup', priority=120)
def add_filters(manager):
from flexget.utils.template import environment
for name, filt in globals().items():
if name.startswith('filter_'):
filtername = name.split('_', 1)[1]
log.debug('adding custom jinja filter %s' % filtername)
environment.filters[filtername] = filt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment