Skip to main content

Block tag decorator for Django templates

Project description

Analogue for simple_tag django decorator for making block (paired) template tags.

Works like django.template.Library.simple_tag() and based on its code. One different is first argument, that takes all content between {% tagname %} and {% endtagname %}

Installation

pip install django-simple-block-tag

Usage

templatetags.py

from simpleblocktag import simple_block_tag
from django import template

register = template.Library()


@simple_block_tag(register)
def mytag(content, attr1, attr2=None):
    return "{}{}{}".format(attr1, content, attr2)


@simple_block_tag(register, takes_context=True)
def save_as(context, content, var_name):
    context[var_name] = content
    return ""

template.html

{% load templatetags %}

{% save_as "var_name" %}Some Content{% endsave_as %}
{% mytag "foo" "bar" %} {{ var_name|lower }} {% endmytag %}

Output

foo some content bar

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-simple-block-tag-0.1.3.tar.gz (2.8 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page