From 655f52491505932ef04264de2bce21a03f3a7cd0 Mon Sep 17 00:00:00 2001 From: Preston Timmons Date: Fri, 8 May 2015 15:10:36 -0500 Subject: Fixed #17085, #24783 -- Refactored template library registration. * 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. --- docs/ref/templates/api.txt | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) (limited to 'docs/ref') diff --git a/docs/ref/templates/api.txt b/docs/ref/templates/api.txt index 4a9a73f758..6ff2dd6c7b 100644 --- a/docs/ref/templates/api.txt +++ b/docs/ref/templates/api.txt @@ -41,7 +41,7 @@ lower level APIs: Configuring an engine ===================== -.. class:: Engine([dirs][, app_dirs][, allowed_include_roots][, context_processors][, debug][, loaders][, string_if_invalid][, file_charset]) +.. class:: Engine([dirs][, app_dirs][, allowed_include_roots][, context_processors][, debug][, loaders][, string_if_invalid][, file_charset][, libraries][, builtins]) .. versionadded:: 1.8 @@ -114,6 +114,34 @@ Configuring an engine It defaults to ``'utf-8'``. + * ``'libraries'``: A dictionary of labels and dotted Python paths of template + tag modules to register with the template engine. This is used to add new + libraries or provide alternate labels for existing ones. For example:: + + Engine( + libraries={ + 'myapp_tags': 'path.to.myapp.tags', + 'admin.urls': 'django.contrib.admin.templatetags.admin_urls', + }, + ) + + Libraries can be loaded by passing the corresponding dictionary key to + the :ttag:`{% load %}` tag. + + * ``'builtins'``: A list of dotted Python paths of template tag modules to + add to :doc:`built-ins `. For example:: + + Engine( + builtins=['myapp.builtins'], + ) + + Tags and filters from built-in libraries can be used without first calling + the :ttag:`{% load %}` tag. + +.. versionadded:: 1.9 + + The ``libraries`` and ``builtins`` arguments were added. + .. staticmethod:: Engine.get_default() When a Django project configures one and only one -- cgit v1.3