Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Library provides additional template tags for django.
Python
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
django_templatetags
MANIFEST.in
README.markdown
runtests.py
setup.py
tox.ini

README.markdown

django-templatetags

Library provides additional template tags for django. For now it is only block tag.

Installation

pip install -e git+git://github.com/un1t/django-templatetags.git#egg=django_templatetags

Easy block tags

Makes block tag. You can create block tag that creates/modifies context or modifies content, but it can't do both.

Example 1: create context

from django_templatetags import AdvancedLibrary

register = AdvancedLibrary()

@register.block_tag
def timeinfo():
    current_time = datetime.datetime.now().strftime('%H:%m')
    return {'current_time': current_time}

{% timeinfo %}
    The time is {{current_time}}
{% endtimeinfo %}

Example 2: takes context

from django_templatetags import AdvancedLibrary

register = AdvancedLibrary()

@register.block_tag(takes_context=True)
def timeinfo(context):
    request = context['request']
    ... 
    return {'current_time': current_time}

{% timeinfo %}
    The time is {{current_time}}
{% endtimeinfo %}

Example 3: modify content

from django_templatetags import AdvancedLibrary

register = AdvancedLibrary()

@register.block_tag(takes_content=True)
def upper(content):
    return content.upper()

{% upper %}
    Lorem ipsum dolor sit amet, consectetur adipiscing elit.
{% endupper %}

Run tests

python runtests.py
Something went wrong with that request. Please try again.