Skip to content

Instantly share code, notes, and snippets.

@NdYAG
Last active December 27, 2023 06:24
Show Gist options
  • Save NdYAG/8553425 to your computer and use it in GitHub Desktop.
Save NdYAG/8553425 to your computer and use it in GitHub Desktop.
Mako Template Sample

Mako Template Syntax Sample

variable, expression

${x}

${len(list_name)}

${pow(x,2) + pow(y,2)}

control flow

if else

% if x == 1:
<div class="">It's One</div>
% elif x == 2:
<div class="">It's Two</div>
% else:
<div class="">Others</div>
% endif

the whitespace between % and 'if else endif' etc., can be omitted.

so %if, %else, %elif, %endif is ok.

for

%for a in [1, 2, 3]:
  <li>${a}</li>
%endfor

Comments

Using ## to comment a line

## <div class="foo"></div>

Inline python codes

There are two kinds:

<%
## python code here
name = 'web-mode'
%>
<%!
  from datetime import datetime
%>

Other tags

self enclose

<%page args="" />
<%include file="" />
<%namespace file="" />
<%inhreit file="" />
<%call expr="" />

explicit closing tag

<%def name="alert()">
## code here
</%def>

<%block name="">
## code here
</%block>
@oronce
Copy link

oronce commented Nov 25, 2021

what kind of value ds_name contain ??
otherwise, my solution would be to store the github_path variable in a python file instead of the template and passed when rendering

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment