Skip to main content

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.

https://travis-ci.org/ojii/django-classy-tags.svg?branch=master

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


Download files

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

Source Distribution

django-classy-tags-0.5.2.tar.gz (18.0 kB view details)

Uploaded Source

Built Distributions

django_classy_tags-0.5.2-py3-none-any.whl (22.7 kB view details)

Uploaded Python 3

django_classy_tags-0.5.2-py2-none-any.whl (22.7 kB view details)

Uploaded Python 2

File details

Details for the file django-classy-tags-0.5.2.tar.gz.

File metadata

File hashes

Hashes for django-classy-tags-0.5.2.tar.gz
Algorithm Hash digest
SHA256 489e29a303be3288a7a0cab4a5b3fcafa1a34472143c1a26d966736b607bf0d3
MD5 b68b02bdc668842cc2d44a8bfb15e972
BLAKE2b-256 43aea35b5b54af9f36fcbbd60bd24505ced927a751773eeea9b2558e85c81e31

See more details on using hashes here.

Provenance

File details

Details for the file django_classy_tags-0.5.2-py3-none-any.whl.

File metadata

File hashes

Hashes for django_classy_tags-0.5.2-py3-none-any.whl
Algorithm Hash digest
SHA256 ab42cd763ce79506e81f55a30fe88f950bddc17c2d2608c88c5cc18ad097aa6b
MD5 212ef40763c6827adbd7c3c1260f20e4
BLAKE2b-256 e59361a59603a18f3cd58b6a68dfbea7e6a49cff4c7f89671fa5014cd33c0219

See more details on using hashes here.

Provenance

File details

Details for the file django_classy_tags-0.5.2-py2-none-any.whl.

File metadata

File hashes

Hashes for django_classy_tags-0.5.2-py2-none-any.whl
Algorithm Hash digest
SHA256 8161e0490f7f86e83bffb248f820c75eb4b21e9b053e7d0172221cdee665aefe
MD5 92bc3d766d3d001152fb38e33e998fa0
BLAKE2b-256 206720cba06e06174c2da9723750edb34adec3ca0a2cb3ab5a3753928fc72380

See more details on using hashes here.

Provenance

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