Class based template tags for django
Python HTML
Latest commit 45d155c Aug 28, 2016 @ojii 0.8.0 release
Permalink
Failed to load latest commit information.
classytags 0.8.0 release Aug 28, 2016
docs removed Python 2.6 support Aug 28, 2016
.coveragerc
.gitignore added __repr__ to Options Dec 6, 2015
.travis.yml
LICENSE initial commit, still missing loads of tests and the docs Aug 4, 2010
README.rst Convert readthedocs links for their .org -> .io migration for hosted … Jun 15, 2016
runtests.py added 1.10 to travis.yml, improved runtests.py Aug 28, 2016
setup.cfg
setup.py removed Python 2.6 support Aug 28, 2016

README.rst

django-classy-tags

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.