mirror of
https://github.com/django/django.git
synced 2025-08-04 10:59:45 +00:00
* Converted the ``libraries`` and ``builtins`` globals of ``django.template.base`` into properties of the Engine class. * Added a public API for explicit registration of libraries and builtins.
This commit is contained in:
parent
7b8008a078
commit
655f524915
49 changed files with 949 additions and 594 deletions
|
@ -13,9 +13,11 @@ available to your templates using the :ttag:`{% load %}<load>` tag.
|
|||
Code layout
|
||||
-----------
|
||||
|
||||
Custom template tags and filters must live inside a Django app. If they relate
|
||||
to an existing app it makes sense to bundle them there; otherwise, you should
|
||||
create a new app to hold them.
|
||||
The most common place to specify custom template tags and filters is inside
|
||||
a Django app. If they relate to an existing app, it makes sense to bundle them
|
||||
there; otherwise, they can be added to a new app. When a Django app is added
|
||||
to :setting:`INSTALLED_APPS`, any tags it defines in the conventional location
|
||||
described below are automatically made available to load within templates.
|
||||
|
||||
The app should contain a ``templatetags`` directory, at the same level as
|
||||
``models.py``, ``views.py``, etc. If this doesn't already exist, create it -
|
||||
|
@ -63,6 +65,15 @@ following::
|
|||
|
||||
register = template.Library()
|
||||
|
||||
.. versionadded:: 1.9
|
||||
|
||||
Alternatively, template tag modules can be registered through the
|
||||
``'libraries'`` argument to
|
||||
:class:`~django.template.backends.django.DjangoTemplates`. This is useful if
|
||||
you want to use a different label from the template tag module name when
|
||||
loading template tags. It also enables you to register tags without installing
|
||||
an application.
|
||||
|
||||
.. admonition:: Behind the scenes
|
||||
|
||||
For a ton of examples, read the source code for Django's default filters
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue