Bitbucket is a code hosting site with unlimited public and private repositories. We're also free for small teams!

Close

django-friendly-tag-loader

Use templatetag libraries in Django templates to optionally support features.

This app provides three template tags {% friendly_load %}, {% if_has_tag %} and {% ifnot_has_tag %}.

Used together you can built templates that have optional support for certain template tags. You can use them if they are available and do something else if they are not.

friendlytagloader has a test suite with 100% coverage and is tested (and passes) against Django 1.2, 1.3 & 1.4 using Python 2.5, 2.6 & 2.7.

Installation

Add friendlytagloader to INSTALLED_APPS

Usage

{% load friendly_loader %} in your template

Load some optional taglib {% friendly_load comments %}

Conditionally use its tag:

{% if_has_tag render_comment_list %}
    {% render_comment_list for obj %}
{% else %}
    Comment support is not available
{% endif_has_tag %}

{% friendly_load %} takes multiple arguments, so loading multiple optional template tag libraries at once is supported:

{% friendly_load comments webdesign website_tags %}

{% if_has_tag %} and {% ifnot_has_tag %} can also handle multiple arguments.

In the case of if_has_tag this means that all given tags should be available, so this will render nothing even though now is a built-in tag:

{% if_has_tag now nonexisting_tag %}
  {% now 'Y' %}
{% endif_has_tag %}

The ifnot_has_tag condition will trigger if any of the given tags is unavailable. For example this will render the message since, even though now is a built-in tag, nonexisting_tag is not available:

{% ifnot_has_tag now nonexisting_tag %}
  Some tags are unavailable.
{% endifnot_has_tag %}

Recent activity

Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.