Skip to main content

Class based template tags for Django

Project description

pypi build coverage

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. Some features:

  • Class based template tags.

  • Template tag argument parser.

  • Declarative way to define arguments.

  • Supports (theoretically infinite) parse-until blocks.

  • Extensible!

Contribute to this project and win rewards

Because this is a an open-source project, we welcome everyone to get involved in the project and receive a reward for their contribution. Become part of a fantastic community and help us make django CMS the best CMS in the world.

We’ll be delighted to receive your feedback in the form of issues and pull requests. Before submitting your pull request, please review our contribution guidelines.

We’re grateful to all contributors who have helped create and maintain this package. Contributors are listed at the contributors section.

Documentation

See REQUIREMENTS in the setup.py file for additional dependencies:

python django

Please refer to the documentation in the docs/ directory for more information or visit our online documentation.

Example

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.

Running Tests

You can run tests by executing:

virtualenv env
source env/bin/activate
pip install -r tests/requirements.txt
python setup.py test

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

Uploaded Source

Built Distribution

django_classy_tags-3.0.1-py3-none-any.whl (14.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: django-classy-tags-3.0.1.tar.gz
  • Upload date:
  • Size: 24.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.10

File hashes

Hashes for django-classy-tags-3.0.1.tar.gz
Algorithm Hash digest
SHA256 d222b45502ac99e550a566667839efaef954b9c7366a6493f143862aabeac878
MD5 354905cd99b8f67cc754fb9388886393
BLAKE2b-256 bd6f65c78169efd2a87ffaca20db1c423ab19cfc75e0ca4af4ea031e46fb80b0

See more details on using hashes here.

Provenance

File details

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

File metadata

  • Download URL: django_classy_tags-3.0.1-py3-none-any.whl
  • Upload date:
  • Size: 14.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.10

File hashes

Hashes for django_classy_tags-3.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0e4a03462b29bd94c8da8160d514cb93e4b4c858752437c082a3efeca94b9f51
MD5 f0837aaaa846819cd1c48cee35997510
BLAKE2b-256 8ed33e1a59e73849dc3493ae0457f4e344a880bdacb53265a60546918f498242

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