jinja_partials icon indicating copy to clipboard operation
jinja_partials copied to clipboard

Bottlepy

Open benboughton1 opened this issue 2 years ago • 1 comments

Is there scope to get this working on bottlepy? My normal stack jinja2 templating in Bottle. I'm half way through the htmx course which is pretty neat and wanted to see if I could get this to work. Cheers

benboughton1 avatar Mar 07 '22 01:03 benboughton1

Hi @benboughton1 I think you could definitely make this happen. You just have to slightly tweak how you initialize the jinja engine and you'd be good to go, from this SO answer:

Two options:

# At startup:
from bottle import BaseTemplate
BaseTemplate.defaults['myglobal'] = 'My global'
# As a request wrapper:
from bottle import Jinja2Template

@hook('before_request')
def before_request():
    Jinja2Template.defaults['myglobal'] = 'My global'

You know Bottle better than me, would this work?

Maybe I could write a register bottle version of this:

https://github.com/mikeckennedy/jinja_partials/blob/31e813008dc60d1e8c0e7c2ad0fb6045ae54009a/jinja_partials/init.py#L58

What do you think?

mikeckennedy avatar Mar 10 '22 05:03 mikeckennedy

Closing this since I think it's gone stale and my recommendation above could fix it. Please let me know if anyone wants me to reopen it.

mikeckennedy avatar Apr 12 '24 16:04 mikeckennedy