Changes between Version 10 and Version 11 of TracDev/PortingFromGenshiToJinja
- Timestamp:
- Feb 23, 2016, 12:21:43 AM (8 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
TracDev/PortingFromGenshiToJinja
v10 v11 112 112 {% if flag %}<b>OK</b>{% else %}<i>!!!</i>{% endif %} 113 113 }}} 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]//.114 However 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]//. 115 115 116 116 === iterate over a collection … … 273 273 </p> 274 274 }}} 275 276 See [http://jinja.pocoo.org/docs/dev/templates/#i18n i18n] doc. 275 277 276 278 Note that only direct variable expansions are supported in `trans` blocks, nothing more complex. … … 311 313 312 314 == Examples 315 316 === Standalone template 313 317 Let's first take a simple full-contained example from the Trac source, the simple index.html / jindex.html templates. 314 318 … … 393 397 **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. 394 398 395 The [#jinjachecker] tool should also help you maintain well-formed templates. 396 399 The [Proposals/Jinja#jinjachecker jinjachecker] tool should also help you maintain well-formed templates. 400 401 402 === "Standard" templates 403 404 By "standard", we mean templates that follow the standard Trac layout, and even adapt to the currently selected theme. 405 406 Instead 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 408 More 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 410 All 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 412 For the jsearch.html example we focus on the //structure// of the templates, the //include// relationship and the decomposition in //blocks//. 413 414 415 But 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. 397 416 398 417