########## Javascript ########## The "javascript" template tag library provides 3 template tags: * javascript_assign: registers some Javascript code. Requires a {% endjavascript_assign %} closing tag. * javascript_render: displays all registered Javascript code * javascript_reset: empties the Javascript registry This template tag library has been written to help template designers implement the following pattern: * in templates, write Javascript fragments along with the corresponding HTML code. This is done with the {% javascript_assign %} template tag. * display the Javascript code at the end of the HTML document. This is done by calling the {% javascript_render %} template tag at the end of the HTML document. * remove duplicate code fragments, e.g. do not call the same library twice. This is done by the {% javascript_render %} template tag. Notice that, at this time, only *strict* duplicates are ignored (i.e. if two Javascript fragments have whitespace or attributes order differences, they won't be considered as duplicate, even if they have the same meaning), so you may have to respect some coding conventions about Javascript. The main advantage of this template tag is that you can manage Javascript code on a per-template basis. You no longer have to maintain both a specific template for HTML code and a global template for all Javascript calls. Let's review an example. We have 3 templates: * base.html: the base template * menu.html: include that display menus * home.html: called when requesting / URL base.html, template code: .. code-block:: django {% load javascript %}
{% javascript_assign %}{% endjavascript_assign %} {% javascript_assign %} {% endjavascript_assign %}This is the content
{% endblock content %} HTML output when requesting / URL (indentation and linebreaks have been cleaned for improved lisibility): .. code-block:: htmlThis is the content