Questions tagged [mako]

Mako is a template library written in Python. It provides a familiar, non-XML syntax which compiles into Python modules for maximum performance. Conceptually, Mako is an embedded Python (i.e. Python Server Page) language.

Mako is a template library written in Python. It provides a familiar, non-XML syntax which compiles into Python modules for maximum performance. Mako's syntax and API borrows from the best ideas of many others, including Django templates, Cheetah, Myghty, and Genshi. Conceptually, Mako is an embedded Python (i.e. Python Server Page) language, which refines the familiar ideas of componentized layout and inheritance to produce one of the most straightforward and flexible models available, while also maintaining close ties to Python calling and scoping semantics.

Mako is used by the python.org website as well as reddit.com. It is the default template language included with the Pylons web framework.

422 questions
4
votes
1 answer

Iterate nested dict in mako template

I have a the following dict: {"name1":{"text":"my text 1", "status":"my status"}, "name2":{"text":"my text 2", "status":"my status"}} Using Mako template, I want to create a html table. I tried the following: Python snippet: test =…
florin
  • 719
  • 12
  • 31
4
votes
3 answers

How can I strip whitespace and newlines with Mako templates? My 12362 line HTML file is killing IE

I'm using the Mako template system in my Pylons website and am having some issues with stripping whitespace. My reasoning for stripping whitespace is the generated HTML file comes out as 12363 lines of code. This, I assume, is why Internet Explorer…
dave
  • 7,717
  • 19
  • 68
  • 100
4
votes
1 answer

Mako Templates : How to find the name of the template which the current template is included by?

I have multiple templates that include each other, such as : t1.html : ... <%include file="t2.html" args="docTitle='blablabla'" /> ... t2.html: <%page args="docTitle='Undefined'"/> ${docTitle} ... And what I want to do is to…
felace
  • 993
  • 1
  • 12
  • 21
4
votes
2 answers

How do I import a local module in a Mako template?

Suppose we have a local python module in the same directory as a mako template: ./my_template.mako ./my_module/module.py How do I import that module into a Mako template that is supposed to be rendered from the command line using mako-render? The…
user1722901
  • 61
  • 1
  • 4
4
votes
1 answer

Jinja2 template compilation information

In mako template engine there is a handy ModuleInfo class: class ModuleInfo(object): """Stores information about a module currently loaded into memory, provides reverse lookups of template source, module source code based on a module's…
alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
4
votes
1 answer

How can I configure vim syntax highlighting for mako templates?

I'd like to get the HTML elements highlighted as well as the MAKO / Python elements. Thanks.
ensnare
  • 40,069
  • 64
  • 158
  • 224
4
votes
3 answers

What should I use - Mako or Django?

I'm making a website that mail users when a movie or a pc game has released. It isn't too complex - users can sign up, choose movies/music or a genre and save the settings. When the movie/music is released - it mails the user. Some other…
Mridang Agarwalla
  • 43,201
  • 71
  • 221
  • 382
4
votes
1 answer

In mako, how can I cycle through a list and display each value?

I have a Python list that I'm supplying to the template: {'error_name':'Please enter a name', 'error_email':'Please enter an email'} And would like to display:
  • Please enter a name
  • Please enter an email
ensnare
  • 40,069
  • 64
  • 158
  • 224
4
votes
6 answers

Converting \n to
in mako files

I'm using python with pylons I want to display the saved data from a textarea in a mako file with new lines formatted correctly for display Is this the best way of doing it? > ${c.info['about_me'].replace("\n", "
") | n}
Joe Gibbons
  • 41
  • 1
  • 2
4
votes
0 answers

Capture value from latex to python using latex

I am using mako and latex in an OpenERP project (using python) and I need to capture the value of \thepage in a python variable, which will consequently be used in an SQL query.
Nant
  • 41
  • 2
4
votes
3 answers

How to track state when iterating in Python's Mako Templates

I want to loop over a list and print the elements seperated by ',', with no trailing comma. I can't just ', '.join(headings) because of the formating and escaping. But the following obviously leaves me with a trailing comma. % for x in headings: …
Brutus
  • 7,139
  • 7
  • 36
  • 41
4
votes
1 answer

Catch mako runtime errors using Bottle

I'm looking for a way to catch mako runtime errors using Bottle. Runtime errors in python are catched using the following code: # main.py from lib import errors import bottle app = bottle.app() app.error_handler = errors.handler ... #…
Andreas
  • 1,211
  • 1
  • 10
  • 21
4
votes
3 answers

Mako Dynamic Template Inheritance

We had this code and it worked fine. After doing a refactor, it doesn't work anymore. Like the comment says, we only want to inherit from a base page if the request isn't an ajax request. To do this, we pass a parameter to the template, and,…
JeffRegan
  • 1,322
  • 9
  • 25
4
votes
2 answers

How to set vars in mako template?

I want to be able to do create a variable "hasBannana" exists only within the mako template html that checks for certain things. Assume grocery and and store were passed in from the function that generated the template. %for customer in…
Rolando
  • 58,640
  • 98
  • 266
  • 407
4
votes
7 answers

Notepad++ loses HTML tags highlighting after any <% of Mako Templates tag. How to disable this behaviour?

Let me attach a picture to explain: So after any tag of Mako (<%block, <%include, ets.) it makes the subsequent HTML code whole sole-colored black. I don't know what to do with this. Options -> Style Options adjustments doesn't help. I've tried to…
Green
  • 28,742
  • 61
  • 158
  • 247