Is it possible to reassign to a new variable name in a Mako template?

81 views
Skip to first unread message

Tom Stratton

unread,
Oct 23, 2012, 6:49:01 PM10/23/12
to mako-d...@googlegroups.com
Hi -

Very new and struggling a little. The Mako community could benefit greatly from more examples on the website - if I every "get it" I'll try to contribute.

I'm trying to use Mako NOT for html page output but to create a relative simple way for a client to format output from another script. What I was hoping to do was pass a dictionary into the render  and then reassign the different pieces of the dict to variable names in the template. 

Seems that if I ever have a ${} on the right hand side of any assignment then I get an error... 

<%
foo= 'some values'
%>
${foo}

works but if I try

<%
foo= ${somevariable}
%>
${foo}


it always generates an error.

Am I simply not going to be able to do this?

Brian Rue

unread,
Oct 23, 2012, 6:51:46 PM10/23/12
to mako-d...@googlegroups.com
Inside the <% %> block it's just regular python code, so you don't need the ${}. Try this:

<%
foo = somevariable
%>
${foo}

You can put any arbitrary python code in the <% %> block... if statements, for loops, imports, define functions, etc.

--
You received this message because you are subscribed to the Google Groups "Mako Templates for Python" group.
To view this discussion on the web visit https://groups.google.com/d/msg/mako-discuss/-/IzwylsOW970J.
To post to this group, send email to mako-d...@googlegroups.com.
To unsubscribe from this group, send email to mako-discuss...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/mako-discuss?hl=en.

Tom Stratton

unread,
Oct 23, 2012, 6:55:03 PM10/23/12
to mako-d...@googlegroups.com
Ahhh ---- 

Thanks for that!

Tom
Reply all
Reply to author
Forward
0 new messages