I recently got into bottlepy and this is pretty much my first experience with a template engine.(Prior I would simply make what I needed in traditional PHP)
My question is this, let's say I have a base layout(A simple HTML/CSS layout), and, for example; a login box on the side. How do I keep the login box dynamically up to date without having to pass values to it on every route?
Take this for example:
from bottle import route,template
@route('/')
def main():
return template("content.tpl") #rebase from layout.tpl
layout.tpl:
<html>
<head>
<title>{{title}}</title>
</head>
<body>
%include
<div id='sidebar'><!-- login box --></div>
</body>
</html>
I guess my main question here is how do I make sure the login box runs without having to insert the variables for it at every single page
To make a variable available in all templates, put something like this before your routes:
from bottle import BaseTemplate
BaseTemplate.defaults['symbol_name'] = value
I use this to add helper functions for my templates.
A more correct solution may involve writing a plugin, which is not terribly difficult and is covered in the Bottle documentation.
Source
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With