mako

how to check if request is ajax in turbogears

How do I go about checking if a request is an ajax request in a controller method in Turbogears? Further, is it possible to return a 'partial' much like in rails or symfony if the request is an ajax request. I know about the json decorator but I need a way to return a partial of a mako template (because I need to format the data and don'...

What are the advantages, if any, to using mako's or pylon's form handlers instead of coding the form manually?

Trying to decide if I should be using mako to handle the forms in my application or not. Thanks for the input. ...

${'foo %(a)s bar %(b)s' % {'a': '1', 'b': '2'}} syntax don't work in mako template

In mako template, I need to do something like that : ${'foo %(a)s bar %(b)s' % {'a': '1', 'b': '2'}} When A do that, I've this error : SyntaxException: (SyntaxError) unexpected EOF while parsing (, line 1) ("'foo %(a)s bar %(b)s' % {'a': '1', 'b': '2'") in file… Do you know a tip to fix this issue ? I need to use this syntax in t...

Mako thinks my template has a 'pass' after an if statement, even though the traceback shows there isn't one

I have Mako taking a template from a preprocessor, and now thinks there is a 'pass' after my if statement. Here is the complete traceback Error ! SyntaxException: (SyntaxError) invalid syntax (, line 1) (u"if ${session['anonymous']}:pass") in file '/.../site/templates/shpaml/views/index.html' at line: 3 char: 1 1 <p>your anonymous stat...

Converting \n to <br> 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", "<br />") | n} ...

What is the proper way to pass errors from classes to rendered html in python

I'm performing all my form validation in a class, and would like to be able to get the errors from the class to the rendered html. One approach I was thinking about was to create a global variable "c" that would store all the errors and to set them from within the class, as I still want the individual methods to return false when they f...

How to use dicts in Mako templates?

Whenever I pass a complicated data structure to Mako, it's hard to iterate it. For example, I pass a dict of dict of list, and to access it in Mako, I have to do something like: % for item in dict1['dict2']['list']: ... %endfor I am wondering if Mako has some mechanism that could replace [] usage to access dictionary elements with simp...

How to define my own functions to use in Mako templates?

How can I make my own function to use in all the Mako templates? For example, I want to create function boda(a, b) that will return a + b. (Toy example.) How can I do this? One way I know that I can do it in template itself: <% def boda(a, b): return a + b %> But I want this function to be globally available to all the templates,...

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: <ul> <li>Please enter a name</li> <li>Please enter an email</li> </ul> ...

What are some good ways (quick to implement and easy to tweak) to create an ajax-enabled form in Pylons?

Are there alternatives to manually coding the JS and HTML? Is there a Pylons-way to do this? Sample code is appreciated. ...

In mako, display a python dict element only if it exists

I'd like to display an error from my python dict "errors" only if it exists. % if c.errors.email: <div class="hint_error">${c.errors.email}</div> % endif But I keep getting the error: AttributeError: 'str' object has no attribute 'email' What am I doing wrong? ...

Pylons/Routes Did url_for() change within templates?

I'm getting an error: GenerationException: url_for could not generate URL. Called with args: () {} from this line of a mako template: <p>Your url is ${h.url_for()}</p> Over in my helpers.py, I do have: from routes import url_for Looking at the Routes-1.12.1-py2.6.egg/routes/util.py, I seem to go wrong about line it calls _screen...

What should I use - Mako or Django?

Hi guys, 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 functionality too but this is the jist. Now, I've been working with Python for a bit but m...

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. ...

Mako template depending on object class?

whats a clean way to use different templates depending on an object class? other than buncha if statements ...

Url for the current page from a Mako template in Pylons

I need to know the full url for the current page from within a Mako template file in Pylons. The url will be using in an iframe contained within the page so it needs to be known when the page is being generated rather than after the page hits the server or from the environment. (Not sure if I am communicating that last bit properly) ...

Mako "Missing parentheses in %def"

In trying to add a cached section to a Mako template, I get the error listed in the above question. Adding () to the end gets rid of the error, but I see no content on my page. Any help is appreciated! <%def name="test" cached="True" cache_timeout="60" cache_type="file"> Test /%def> ...

Mako templates inline if statement

I have a template variable, c.is_friend, that I would like to use to determine whether or not a class is applied. For example: if c.is_friend is True <a href="#" class="friend">link</a> if c.is_friend is False <a href="#">link</a> Is there some way to do this inline, like: <a href="#" ${if c.is_friend is True}class="friend"{/if}>li...

Conditional operator in Mako using Pylons

In PHP, I often use the conditional operator to add an attribute to an html element if it applies to the element in question. For example: <select name="blah"> <option value="1"<?= $blah == 1 ? ' selected="selected"' : '' ?>> One </option> <option value="2"<?= $blah == 2 ? ' selected="selected"' : '' ?>> Two ...

Better error reporting mako

Is there a way to add tempate string which contains error to mako`s error trace? ...