Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 92cfb70

Browse filesBrowse files
committed
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.
1 parent 0e643b2 commit 92cfb70
Copy full SHA for 92cfb70

File tree

Expand file treeCollapse file tree

1 file changed

+37
-0
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+37
-0
lines changed

‎docs/scenarios/web.rst

Copy file name to clipboardExpand all lines: docs/scenarios/web.rst
+37Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,43 @@ you can replace it with a more terse and readable syntax that uses the pattern
473473
But keep in mind that the full `<span tal:replace="expression">Default Text</span>`
474474
syntax also allows for default content in the unrendered template.
475475

476+
Mako
477+
----
478+
`Mako <http://www.makotemplates.org/>`_ is a template language that compiles to Python
479+
for maximum performance. Its syntax and api is borrowed from the best parts of other
480+
templating languages like Django and Jinja2 templates. It is the default template
481+
language included with the `Pylons and Pyramid <http://www.pylonsproject.org/>`_ web
482+
frameworks.
483+
484+
An example template in Mako looks like:
485+
486+
.. code-block:: html
487+
488+
<%inherit file="base.html"/>
489+
<%
490+
rows = [[v for v in range(0,10)] for row in range(0,10)]
491+
%>
492+
<table>
493+
% for row in rows:
494+
${makerow(row)}
495+
% endfor
496+
</table>
497+
498+
<%def name="makerow(row)">
499+
<tr>
500+
% for name in row:
501+
<td>${name}</td>\
502+
% endfor
503+
</tr>
504+
</%def>
505+
506+
To render a very basic template, you can do the following:
507+
508+
.. code-block:: python
509+
510+
from mako.template import Template
511+
print(Template("hello ${data}!").render(data="world"))
512+
476513
.. rubric:: References
477514

478515
.. [1] `The mod_python project is now officially dead <http://blog.dscpl.com.au/2010/06/modpython-project-is-now-officially.html>`_

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.