<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Django Dev &#187; templatetag</title>
	<atom:link href="http://django-dev.com/tag/templatetag/feed" rel="self" type="application/rss+xml" />
	<link>http://django-dev.com</link>
	<description>About Django development</description>
	<lastBuildDate>Sun, 20 Jun 2010 18:23:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Accept template tags in Django Flatpages</title>
		<link>http://django-dev.com/accept-template-tags-in-django-flatpages-2010-06</link>
		<comments>http://django-dev.com/accept-template-tags-in-django-flatpages-2010-06#comments</comments>
		<pubDate>Sun, 20 Jun 2010 18:23:00 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Tips]]></category>
		<category><![CDATA[flatpages]]></category>
		<category><![CDATA[template]]></category>
		<category><![CDATA[templatetag]]></category>

		<guid isPermaLink="false">http://django-dev.com/?p=16</guid>
		<description><![CDATA[You need to use template tags in Django FlatPages application ? Here is a solution: First create an evaluate_tag.py file in your templatetags directory with the following content: [python] from django import template register = template.Library() @register.tag(name="evaluate") def do_evaluate(parser, token):     """     tag usage {% evaluate object.textfield %}     """   [...]]]></description>
			<content:encoded><![CDATA[<p>You need to use template tags in <a href="http://docs.djangoproject.com/en/dev/ref/contrib/flatpages/">Django FlatPages</a> application ?</p>
<p>Here is a solution:</p>
<p>First create an <strong>evaluate_tag.py</strong> file in your <strong>templatetags </strong>directory with the following content:</p>
<pre><code>
[python]
from django import template

register = template.Library()

@register.tag(name="evaluate")
def do_evaluate(parser, token):
    """
    tag usage {% evaluate object.textfield %}
    """
    try:
        tag_name, variable = token.split_contents()
    except ValueError:
        raise template.TemplateSyntaxError, "%r tag requires a single argument" % token.contents.split()[0]
    return EvaluateNode(variable)

class EvaluateNode(template.Node):
    def __init__(self, variable):
        self.variable = template.Variable(variable)

    def render(self, context):
        try:
            content = self.variable.resolve(context)
            t = template.Template(content)
            return t.render(context)
        except template.VariableDoesNotExist, template.TemplateSyntaxError:
            return 'Error rendering', self.variable
[/python]
</code></pre>
<p>Next, modifiy your flatpages template file to use this template tag:</p>
<p>[html]</p>
<p>&lt;!DOCTYPE HTML PUBLIC &#8220;-//W3C//DTD HTML 4.0 Transitional//EN&#8221;<br />
&#8220;http://www.w3.org/TR/REC-html40/loose.dtd&#8221;&gt;<br />
&lt;html&gt;<br />
&lt;head&gt;<br />
&lt;title&gt;{{ flatpage.title }}&lt;/title&gt;<br />
&lt;/head&gt;<br />
&lt;body&gt;<br />
{% load evaluate_tag %}<br />
{% evaluate flatpage.content %}<br />
&lt;/body&gt;<br />
&lt;/html&gt;</p>
<p>[/html]</p>
<p>Now, you can use template tags in your flatpages !</p>
]]></content:encoded>
			<wfw:commentRss>http://django-dev.com/accept-template-tags-in-django-flatpages-2010-06/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
