Skip to content

Instantly share code, notes, and snippets.

@oschettler
Created September 27, 2013 07:20
Show Gist options
  • Save oschettler/6725179 to your computer and use it in GitHub Desktop.
Save oschettler/6725179 to your computer and use it in GitHub Desktop.
A simple class to include blocks of code in a template for bottle.py
class Block:
'''
A simple block class for Bottle templates.
Usage:
Pass a named block into your template by returning it from an action:
return dict(scripts = Block('scripts'))
In your template, use it like this:
%from bottle import template
%scripts.append(template('path/to/sub-template', var=value))
In your layout, include the aggregated scripts:
%if defined('scripts'):
{{!scripts()}}
%end
'''
name = 'block'
text = ''
def __init__(self, name):
self.name = name
self.text = ''
def append(self, text):
self.text += text
def __call__(self):
return self.text
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment