7

how can I add a custom filter to be used in a jinja template used by cookiecutter?

I tried adding using a pre_gen_project hook, it's called, but I can't find a way to make my python functions visible as jinja filters (or function) inside the templates.

coffee-grinder
  • 26,940
  • 19
  • 56
  • 82
José Ricardo
  • 1,479
  • 1
  • 14
  • 28
  • Have you read the jinja2 [docs](http://jinja.pocoo.org/docs/dev/api/#writing-filters)? – doru Apr 30 '15 at 12:10
  • Yes, using the filter decorators didn't work nor adding to a new enviroment's filter dict. I must be missing something. – José Ricardo Apr 30 '15 at 15:41
  • you should show your filter code and how you call your filter in jinja2 env – Frenchy Dec 24 '21 at 14:24
  • This is possible using local extensions. See https://cookiecutter.readthedocs.io/en/latest/advanced/local_extensions.html – Robbert Apr 03 '23 at 09:20

0 Answers0