Documentation

Basics

You have to use two-space indentation.

A tag's contents can start on the same line as its definition:

%title Page title

Alternatively, you can put the contents on a new, indented line:
%title
  Page title

A closed tag can be created by appending a '/' right after tag name:

%br/

Tag attributes can be added by appending a ':' after the tag definition.
The rest of the line will interpreted as a Python dictionary which contains
the attribute definitions.

%a: 'href': 'http://...', 'target': '_blank'

In this case you can only specify the contents of the tag on a new line.
If the value of a tag is the Python object "None" the attribute is ignored.
%hr/: 'style': style if hasstyle else None
=>
if hasstyle: <hr style="..." />
else: <hr />

ReML has a shortcut for 'id' and 'class' attributes:

%div#footer  =>  <div id="footer">
%div#myid.sidebar.container  =>  <div id="myid" class="sidebar container">

If an expression starts with '#' or '.' a div is assumed:
#footer  =>  <div id="footer">
.sidebar.container  =>  <div class="sidebar container">

Python code can be inserted by starting an expression with '- '

- if text.startswith('hello '):
  - text = text[6:]

You can insert the result of an evaluation by starting an expression with '= '
= text.strip()

Note that you have to add a single space after the '-' and '=' characters.

You can escape evaluation by putting a '\' at the beginning of the expression:

\%...  =>  %...

Similarly, you can escape newlines by putting a '\' at the end of the line:
...a\
...b...
=>
...a...b...

HTML escaping

Evaluation expressions and attribute values automatically escape the following
characters:

& => &amp;
> => &gt;
< => &lt;
" => &quot;
' => &#39;

Surround a full expression with unescaped() to override this behavior:
= unescaped(...)
%a: 'href': unescaped(...)

Multi-file templates

ReML doesn't support template inheritance, but for now it has an alternative
that should work for many sites: includes. Let's see an example:

### somepage.reml
- append('master.reml')
- title = 'Some page'
- def extrascripts():
  %link/: 'href': 'extra.css", 'rel': 'stylesheet', 'type': 'text/css'
- def contents():
  %h1 Introduction
  ReML is the Reduction Markup Language.

### master.reml
%html
  %head
    %title= title
    - extrascripts()
  %body
    #header ReML -- do more with less
    .contents
      - contents()
    #footer Copyright 2008 Waldemar Kornewald

The following two functions are available:

insert() can be used to insert the given template name into the current
position:

%table
  - insert('table_contents.reml')

append() is the same as putting insert() at the end of the file. It was added
to improve readability.

Using ReML

Just copy reml.py into your project folder, so it can be imported by your other code. Here is a sample snippet:

from reml import TemplateLoader
data = {'username': 'hacker'}
print TemplateLoader('/path/to/templates').load('about.reml').render(data)

This will print the rendered template stored in the file "about.reml". The TemplateLoader optionally takes another TemplateLoader instance as a second argument which allows for chaining multiple loaders.

page_revision: 4, last_edited: 1202647557|%e %b %Y, %H:%M %Z (%O ago)
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License