Using Webhelpers in mako template in Pyramid

1.5k views Asked by At

How do I use Webhelpers in a Mako template in my Pyramid app?


In Pylons I had global helper variable h to use in my templates so I could simply do:

${h.stylesheet_link("/css/default.css")}

given I import stylesheet_link from webhelpers.html.tags in Pylons lib/helpers.py

I don't want to go with Akhet and replicate full Pylons behavior but simply I'd like to get some base (recommended?) usage of a package that's (cite) officially endorsed, but not Pyramid add-on.

1

There are 1 answers

1
Rick On BEST ANSWER

The cookbook in the docs refers to this here

http://docs.pylonsproject.org/projects/pyramid_cookbook/en/latest/templates/templates.html

You basically inject the helpers using a before-render event so that it's available in your templates. Hope that helps.