Class based template tags for Django
Project description
Please refer to the documentation in the docs/ directory for help. For a HTML rendered version of it please see here.
About this project
The goal of this project is to create a new way of writing Django template tags which is fully compatible with the current Django templating infrastructure. This new way should be easy, clean and require as little boilerplate code as possible while still staying as powerful as possible.
Features
Class based template tags.
Template tag argument parser.
Declarative way to define arguments.
Supports (theoretically infinite) parse-until blocks.
Extensible!
For the impatient
This is how a tag looks like using django-classy-tags:
from classytags.core import Options from classytags.helpers import AsTag from classytags.arguments import Argument from django import template register = template.Library() class Hello(AsTag): options = Options( Argument('name', required=False, default='world'), 'as', Argument('varname', required=False, resolve=False) ) def get_value(self, context, name): return 'hello %s' % name register.tag(Hello)
That’s your standard hello world example. Which can be used like this:
{% hello %}: Outputs hello world
{% hello "classytags" %}: Outputs hello classytags
{% hello as myvar %}: Outputs nothing but stores hello world into the template variable myvar.
{% hello "my friend" as othervar %}: Outputs nothing but stores hello my friend into the template variable othervar.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for django_classy_tags-0.7.1-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | aeb544f720402583280573312b8c11588ef85cd15c769705aad85c47f8e3045e |
|
MD5 | e5c74156c3e6dd8e66c960e060ca1031 |
|
BLAKE2b-256 | eefea4af1c86da5eb731aaeb9dcf8a52dad8af69ff509d930130382cc868ad0d |