--- title: Mako category: Python layout: 2017/sheet --- ### Basic usage ``` Variable x has content: ${x} Expression: ${x + 1} Escaped for HTML: ${x | h} ``` ### Control structures ``` % for x in range(5): % if x % 2 == 0: ${x} is even! % else: ${x} is odd! % endif % endfor ``` ### Including Python code ```python <% greeting = "Hello world!" # arbitrary python code %> <%! # arbitrary python code run at toplevel # cannot access variables! def sign_string(number): if number > 0: return "positive" elif number < 0: return "negative" else: return "zero" %> ``` ### Special blocks ```html <%text filter="h"> This is a raw block where ${nothing is evaluated} <% not even this %> and too with "h" filter %text> <%def name="myfunc(x)"> this is a reusable macro, with arguments: ${x} %def> ${myfunc(42)} <%doc> this is a comment %doc> ``` ### Inheritance #### shared.html ```html