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.7.2.tar.gz (17.6 kB view details)

Uploaded Source

Built Distribution

django_classy_tags-0.7.2-py2.py3-none-any.whl (22.1 kB view details)

Uploaded Python 2 Python 3

File details

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

File metadata

File hashes

Hashes for django-classy-tags-0.7.2.tar.gz
Algorithm Hash digest
SHA256 068506291979ca973f74eb5744359fb319d4aa891cd0081c59da09b0e50ea094
MD5 34c6a6eb9fd0ecbc452e688afe03b2e0
BLAKE2b-256 1b0f9eaa1cc7a6d994f299e613fe0937aca3b4a8fd319625186e57e3704c3ff7

See more details on using hashes here.

Provenance

File details

Details for the file django_classy_tags-0.7.2-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for django_classy_tags-0.7.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 9b21579ef0fcc2258e5397ff9134150e58d0482aef0c28b7e7369cbf35074a8c
MD5 403082f225e6eea4ce555ff65d8eb521
BLAKE2b-256 068ab88ec64b42236e4618861a62a334346daf1e9174cd406b50fd1073bad97e

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