简体   繁体   中英

Using Webhelpers in mako template in Pyramid

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM