Source

flatland / docs / source / templating / jinja2.rst

Jinja2 Templates

Markup Generator Usage

Printing an input tag:

>>> import flatland
>>> from flatland.out.markup import Generator
>>> gen = Generator()
>>> el = flatland.String('foo', name='thinger')
>>> print gen.input(el)
<input name="thinger" value="foo" />

It's quite simple to output any tag you need with flatland:

>>> from flatland.out.markup import Generator
>>> from jinja2 import Template
>>> template = Template('''\
... Hi I'm a generator, see my tag: {{ gen.tag('a', href='#') }}
... ''')
>>> gen = Generator()
>>> print template.render(gen=gen)
Hi I'm a generator, see my tag: <a href="#" />

There's also no requirement that these tags exist in any current standard:

>>> from flatland.out.markup import Generator
>>> gen = Generator()
>>> print gen.tag('wookie', contents="wookies are not really real")
<wookie>wookies are not really real</wookie>

In Progress

Support for Jinja2 and Mako is underway with a feature set similar to the Genshi support.

Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.