| 405 | |
| 406 | In fact, no changes to the `IRequestHandler` interface were needed. |
| 407 | |
| 408 | |
| 409 | === Replacing the `ITemplateStreamFilter` interface #ReplacingITemplateStreamFilter |
| 410 | |
| 411 | One of the strengths of Genshi was its ability to transform the normal HTML content and, for example, to inject arbitrary content at any point in the HTML, thanks to the use of the Transform stream filter and its API. |
| 412 | |
| 413 | With Jinja2, the content is produced in one step, with no kind of post-processing. Hence the content should either be produced right away, or if it really has to be produced as an extra step, it should be produced dynamically on client-side using JavaScript. |
| 414 | |
| 415 | ==== Producing the correct content directly |
| 416 | |
| 417 | There were two post-processing steps from which plugin writers did benefit, possibly unknowingly: |
| 418 | 1. the addition of the `__FORM_TOKEN` hidden parameter to <form> elements, necessary for successful POST operations |
| 419 | 2. accessibility key enabling/disabling (TODO) |
| 420 | |
| 421 | As this no longer happen, it's now the responsibility of plugin writers to add this <input> in their content. This is simple enough: |
| 422 | {{{#!html+jinja |
| 423 | <form action="#" method="post"> |
| 424 | <input type="hidden" name="__FORM_TOKEN" value="${form_token}" /> |
| 425 | ... |
| 426 | </form> |
| 427 | }}} |
| 428 | This gets even simpler thanks to a default macro: |
| 429 | {{{#!html+jinja |
| 430 | <form action="#" method="post"> |
| 431 | ${jmacros.form_token_input()} |
| 432 | ... |
| 433 | </form> |
| 434 | }}} |
| 435 | |
| 436 | The `jmacros` corresponds to the [source:cboos.git/trac/templates/jmacros.html@jinja2 trac/templates/jmacros.html] default macros, and this file is included by default (in `jlayout.html`), so you don't have to bother to include it yourself (as most of the templates will extend `jlayout.html`). |
| 437 | |
| 438 | |
| 439 | ==== Hooking into the HTML content produced by other templates |
| 440 | |
| 441 | On this day, 127/898 plugins (14.1%) on trac-hacks.org make use of `filter_stream()` from the `ITemplateStreamFilter` interface. |
| 442 | |
| 443 | So this means this specific step of the migration, perhaps the less straightforward, will be of interest for most plugin developers. |
| 444 | |
| 445 | Note that though it wouldn't harm to leave the code for `ITemplateStreamFilter` around for use by Trac < 1.4, the new suggested way also works great with earlier versions of Trac (1.0 and 1.2, perhaps even 0.12), so there's really no reason to maintain both versions once you did the switch. |
| 446 | |
| 447 | |
| 448 | |