From 92cfb70e877c1dc3813d6706766a95d9c501ed91 Mon Sep 17 00:00:00 2001 From: SanketDG Date: Mon, 26 Oct 2015 13:35:10 +0530 Subject: [PATCH] add Mako to templating section http://www.makotemplates.org/ Mako is the default templating language included in the pyramid and pylons web frameworks. This includes a short info on how to get started writing templates in Mako. --- docs/scenarios/web.rst | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/docs/scenarios/web.rst b/docs/scenarios/web.rst index 9a5c7603b..ae79fb20e 100644 --- a/docs/scenarios/web.rst +++ b/docs/scenarios/web.rst @@ -473,6 +473,43 @@ you can replace it with a more terse and readable syntax that uses the pattern But keep in mind that the full `Default Text` syntax also allows for default content in the unrendered template. +Mako +---- +`Mako `_ is a template language that compiles to Python +for maximum performance. Its syntax and api is borrowed from the best parts of other +templating languages like Django and Jinja2 templates. It is the default template +language included with the `Pylons and Pyramid `_ web +frameworks. + +An example template in Mako looks like: + +.. code-block:: html + + <%inherit file="base.html"/> + <% + rows = [[v for v in range(0,10)] for row in range(0,10)] + %> + + % for row in rows: + ${makerow(row)} + % endfor +
+ + <%def name="makerow(row)"> + + % for name in row: + ${name}\ + % endfor + + + +To render a very basic template, you can do the following: + +.. code-block:: python + + from mako.template import Template + print(Template("hello ${data}!").render(data="world")) + .. rubric:: References .. [1] `The mod_python project is now officially dead `_