changed template paths in settings (takes into account the theme)
[myslice.git] / portal / templatetags / portal_filters.py
1 from django import template
2 from django.template.loader_tags import do_include
3 from myslice.settings import theme
4
5 register = template.Library()
6
7 class IncludeNode(template.Node):
8     
9     def __init__(self, template_name):
10         if theme :
11             self.theme_template_name = "%s%s" % (theme, template_name)
12         self.template_name = template_name
13
14     def render(self, context):
15         try:
16             # Loading the template and rendering it
17             included_template = template.loader.get_template(self.theme_template_name).render(context)
18         except template.TemplateDoesNotExist:
19             # template theme does not exists, try the generic one
20             try:
21                 # Loading the template and rendering it
22                 included_template = template.loader.get_template(self.template_name).render(context)
23             except template.TemplateDoesNotExist:
24                 included_template = ''
25                 
26         return included_template
27
28 @register.tag
29 def widget(parser, token):
30     """Usage: {% widget "widget.html" %}
31
32     This will fail silently if the template doesn't exist. If it does, it will
33     be rendered with the current context."""
34     try:
35         tag_name, template_name = token.split_contents()
36     except ValueError:
37         raise template.TemplateSyntaxError, \
38             "%r tag requires a single argument" % token.contents.split()[0]
39
40     return IncludeNode(template_name[1:-1])