def direct_to_template_subdir(request, template, subdir = None, **kwargs):
"""
A wrapper around django's direct_to_template view. It prepend a
given file path on to the template we are given. This lets us
render templates in a sub-dir of the url pattern that matches this
template.
What do I mean?
Take for example:
url(r'^foo/(?P<template>.*\.html)$', direct_to_template,
{'subdir' : 'subdir/'}),
Which will template any url that matches <parent url>/foo/bar.html for any
'bar'. The problem is if this is a sub-url pattern match this is going to
look for the template "bar.html" when we may actually want it to get the
template "<parent url>/foo/bar.html"
Arguments:
- `request`: django httprequest object...
- `template`: The template to render.
- `subdir`: The subdir to prepend to the template.
- `**kwargs`: kwargs to pass in to
"""
if subdir is not None:
template = os.path.join(subdir,template)
return direct_to_template(request, template, **kwargs)
Comments