mako

Template tags like Django with Mako and Pylons

Hi to all, For my site need some "widgets" that elaborate output from various data models, because this widgets are visible in any page is possible with mako to retrieve the data without pass (and elaborate) every time with render() in controllers? ...

Disable (mako) template caching in Pylons 1.0

I recently jumped on a project using Pylons. I'm not familiar with either Python or Pylons, but I haven't had very much trouble getting the hang of things. Pylon projects seem to cache templates indefinitely by default and I can't figure out a way to clear the cached templates (stored by default in /data/templates) except by manually de...

Pylons TextMate Bundle

I am looking for a TextMate Bundle for Pylons development. Does anyone know of an existing bundle for Mako and/or SQLAlchemy. I found these two existing articles but the links are no longer valid If someone knows of a currently active link please let me know Thanks ...

how to deal with unicode in mako?

I constantly get this error using mako: UnicodeEncodeError: 'ascii' codec can't encode character u'\xe0' in position 6: ordinal not in range(128) I've told mako I'm using unicode in any possible way: mylookup = TemplateLookup( directories=['plugins/stl/templates'], input_encoding='utf-8', output_encoding='...

How do I get some string values from Pylons controller be assigned to JavaScript variables with Mako?

I'm developing under Pylons using Mako templates. The problem is that I need to assign a string from some attribute of tmpl_context to a JavaScript variable in a page body. The additional problem is that this string can be quite arbitrary, ie can contain such characters like ", ', <, >, etc... Is there a common way to do such assignment?...

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

Hi. 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'"/> <title>${docTitle}</title> ... And what I want to do is to determine that t2 is included by t1 (or another one, so I can use its name). No specifi...

Mako or Jinja2 ?

I didn't find a good comparison of jinja2 and Mako. What would you use for what tasks ? I personnaly was satisfied by mako (in a pylons web app context) but am curious to know if jinja2 has some nice features/improvements that mako doesn't ? -or maybe downsides ?- ...

Loading mako templates from files

I'm new to python and currently trying to use mako templating. I want to be able to take an html file and add a template to it from another html file. Let's say I got this index.html file: <html> <head> <title>Hello</title> </head> <body> <p>Hello, ${name}!</p> </body> </html> and this name.html file: world (yes, it just ...

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 is hanging when it tries to load it. I want to be able to have my HTML file look nice an...

Python / Mako : How to get unicode strings/characters parsed correctly ?

Hi. I'm trying to get Mako render some string with unicode characters : tempLook=TemplateLookup(..., default_filters=[], input_encoding='utf8',output_encoding='utf-8', encoding_errors='replace') ... print sys.stdout.encoding uname=cherrypy.session['userName'] print uname kwargs['_toshow']=uname ... return tempLook.get_template(page).re...

Mako templates using Django template tags

Our Django site is built using Mako templates. We want to use a third party project called django-socialregistration, but its template tags use Django's templates. If we used Django templates we could just {% load facebook_tags %} {% facebook_button %} {% facebook_js %} How can I do the same thing in Mako? You can inline strait up py...

Python class-dependent template?

i want to create a widget depending on the class of the object, is there a simple way to do that in mako? for example class A might have attributes A and B while class B might have attributes A, B and C is there a pattern for this? i want to make a super class that they but inherit, but if I have a function print and call it by cal...

Getting %def references in mako python

is there a way to use %def references somehow, basic idea being: % if condition_a: % func = %def_a % elif condition_b: % func = %def_b ... etc ... ${func( params )} ...

Python lookup function

I want to set up a lookup function with mako. on top of the template, i have <%! lookup = { 'key': function } %> <%def name="function()"> Output </%def> so i can use it later <%def name="body()"> ${lookup['key']()} </%def> this gives me a function is not a defined error. can i get around this? i know why it doesn'...

Mako calling function from string?

Is there an easy way to call a function given a string name in mako? ...

Pylons + Mako -- Access POST data from templates

How can I access my request.params post data from my Mako template with Pylons? ...

Strip whitespace from Mako template output (Pylons)

Hi guys, I'm using Mako + Pylons and I've noticed a horrendous amount of whitespace in my HTML output. How would I go about getting rid of it? Reddit manage to do it. ...

Named replaces in strings with Mako

Hello, When creating a template in Mako, I would need to write things like : ${_('Hello, %(fname)s %(lname)s') % {'fname':'John','lname':'Doe'}} I keep getting SyntaxException: (SyntaxError) unexpected EOF while parsing when writing that. Is there wny way to do the same ? ${_('Hello, %s %s') % ('John', 'Doe')} works, but it does not a...

Truncate a string in mako template

I'd like to find a way to get a title to truncate if too long, like this: 'this is a title' 'this is a very long title that ...' Is there a way to print a string in mako, and automatically truncate with "..." if greater than a certain number of characters? Thanks. ...

Condition mako base template from inheriting one

I have a base.mako template with a if statement to include or not jQuery <head> % if getattr(c, 'includeJQuery', False): <script type="text/javascript" src="jquery.js"></script> % endif ... Several templates inherit from base.mako, someone needs jQuery, someone don't. At the moment I have to set the attribute in the controller be...