Edgewall Software

Changes between Version 10 and Version 11 of TracDev/PortingFromGenshiToJinja


Ignore:
Timestamp:
Feb 23, 2016, 12:21:43 AM (8 years ago)
Author:
Christian Boos
Comment:

overview of #Standardtemplates and links to specific examples

Legend:

Unmodified
Added
Removed
Modified
  • TracDev/PortingFromGenshiToJinja

    v10 v11  
    112112{% if flag %}<b>OK</b>{% else %}<i>!!!</i>{% endif %}
    113113}}}
    114 However this goes against readability and processing via the [#jinjachecker] tool,  so we really advise that you stick to the use of //[http://jinja.pocoo.org/docs/dev/templates/#line-statements line statements]//.
     114However this goes against readability and processing via the [Proposals/Jinja#jinjachecker jinjachecker] tool,  so we really advise that you stick to the use of //[http://jinja.pocoo.org/docs/dev/templates/#line-statements line statements]//.
    115115
    116116=== iterate over a collection
     
    273273                </p>
    274274   }}}
     275
     276See [http://jinja.pocoo.org/docs/dev/templates/#i18n i18n] doc.
    275277
    276278Note that only direct variable expansions are supported in `trans` blocks, nothing more complex.
     
    311313
    312314== Examples
     315
     316=== Standalone template
    313317Let's first take a simple full-contained example from the Trac source, the simple index.html / jindex.html templates.
    314318
     
    393397**Never** go back to the bad old Clearsilver habits were sometimes the logic in those templates took advantage of the lack of well-formedness constraints, e.g. by conditionally inserting end/start pairs of tags. Such templates were hard to maintain, and you always have cleaner alternatives.
    394398
    395 The [#jinjachecker] tool should also help you maintain well-formed templates.
    396 
     399The [Proposals/Jinja#jinjachecker jinjachecker] tool should also help you maintain well-formed templates.
     400
     401
     402=== "Standard" templates
     403
     404By "standard", we mean templates that follow the standard Trac layout, and even adapt to the currently selected theme.
     405
     406Instead of the Genshi way of including a template containing filters, the Jinja2 way follows an "object oriented" approach, with inheritance and overriders. Consider that some named sections (or "blocks") of the base template are similar to "methods", imagine that you only have to "subclass" this base template and "reimplement" the overridable methods with your specific content, and there you have it.
     407
     408More specifically, you'll have to "extend" the [source:cboos.git/trac/templates/jlayout.html@jinja2 jlayout.html] template, and redefine the "head", and "content" blocks if needed.
     409
     410All the details are available in Proposals/Jinja#Jinja2theme, including a walkthrough for the specific example of the [source:cboos.git/trac/search/templates/jsearch.html@jinja2 jsearch.html] template.
     411
     412For the jsearch.html example we focus on the //structure// of the templates, the //include// relationship and the decomposition in //blocks//.
     413
     414
     415But we also have a complete conversion example, in Proposals/Jinja#Conversionexample, which displays the Genshi wiki_view.html template and the Jinja2 jwiki_view.html template side-by-side, along with comments explaining the conversion choices.
    397416
    398417