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 details)

Uploaded Source

File details

Details for the file django-simple-block-tag-0.1.3.tar.gz.

File metadata

File hashes

Hashes for django-simple-block-tag-0.1.3.tar.gz
Algorithm Hash digest
SHA256 4fed9ac0b20497cfa428312339eb1c1a6c71760d735d84d34a612ac85724aa9c
MD5 d5ed57e16ce835756524f84f1897844e
BLAKE2b-256 d9b2f5a8edc44b799981ccf513733aa00cc5c9e9149ce56b944b50e37975ef9b

See more details on using hashes here.

Supported by

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