Edgewall Software

Changes between Version 1 and Version 2 of WorkInProgress/PluggableDirectivesLibraries/TextTemplates


Ignore:
Timestamp:
Jun 11, 2010 9:11:09 PM (6 years ago)
Author:
Carsten Klein <carsten.klein@…>
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • WorkInProgress/PluggableDirectivesLibraries/TextTemplates

    v1 v2  
    1818embedding Python code in templates.
    1919
    20 .. note:: Actually, Genshi currently has two different syntaxes for text
    21           templates languages: One implemented by the class ``OldTextTemplate``
    22           and another implemented by ``NewTextTemplate``. This documentation
    23           concentrates on the latter, which is planned to completely replace the
    24           older syntax. The older syntax is briefly described under legacy_.
    25 
    2620.. _django: http://www.djangoproject.com/
    2721
     
    4741effectively treated as a comment.
    4842
     43An exception to that rule is the {% namespace %} directive.
     44Namespace declarations are considered one line statements that will enhance
     45text templates by provision of additional directives defined in so-called
     46directive libraries.
     47
    4948If you want to include a literal delimiter in the output, you need to escape it
    5049by prepending a backslash character (``\``).
     50
     51.. Note: Directives libraries are similar to JSP tag libraries and are a new feature
     52         of Genshi.
     53
     54
     55Namespaces
     56==========
     57
     58.. _`namespace`:
     59
     60``{% namespace %}``
     61-------------------
     62
     63Declares a new namespace for use with Genshi directives. Individual directives
     64being used in the template will have to be prefixed by the namespace alias
     65defined as part of the namespace declaration.
     66
     67The default namespace is "http://genshi.edgewall.org/". All non prefixed
     68directives will be looked up from that namespace. If a prefix was defined,
     69and there is also a valid namespace declaration for it, then that namespace
     70will be used instead for looking up the directive.
     71
     72.. code-block:: genshitext
     73 
     74  {% namespace "http://genshi.edgewall.org/" %}
     75  {% namespace py "http://genshi.edgewall.org/" %}
     76  {% namespace foo "http://foo.example.org/" %}
     77
     78  # use if directive from default namespace
     79
     80  {% if ... %}
     81
     82  # use bar directive from foo namespace
     83
     84  {% foo:bar ... %}
     85
     86  # use if directive (from default namespace)
     87
     88  {% py:if ... %}
     89
     90More information on directives libraries can be found
     91under `Pluggable Directives Libraries <directives_libraries.html>`_.
     92
    5193
    5294