At the moment override_template only works for the "text/html" engine, this small patch allows it to work for other content types.
As an example I use override_template to have a single controller serving javascripts generated at runtime from templates and return the result with a content_type of "text/javascript".
@expose(content_type='text/javascript')
def parsedjs(self, script):
"""
Render the required javascript from a template of the same name (but
with a .mak extension) as found in spam/templates/parsedjs/
This is needed for javascripts that use config variables from spam or
other variable data.
"""
scriptname = os.path.splitext(script)[0]
templatename = 'spam.templates.parsedjs.%s' % scriptname
if config.get('use_dotted_templatenames', False):
template = G.dotted_filename_finder.get_dotted_filename(
templatename, template_extension='.mak')
if not os.path.exists(template):
raise HTTPNotFound
override_template(self.parsedjs, 'mako:%s' % templatename)
return dict()