Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: README.md

Issue 29328184: Issue 3092 - Support use of Jinja2 template inheritance (Closed)
Patch Set: Created Sept. 18, 2015, 11:06 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | cms/converters.py » ('j') | cms/converters.py » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # CMS # 1 # CMS #
2 2
3 We use this CMS for [adblockplus.org](https://github.com/adblockplus/web.adblock plus.org/) 3 We use this CMS for [adblockplus.org](https://github.com/adblockplus/web.adblock plus.org/)
4 and related websites. It converts a directory with content data into static 4 and related websites. It converts a directory with content data into static
5 files. You are free to use it for other projects but please keep in mind that we 5 files. You are free to use it for other projects but please keep in mind that we
6 make no stability guarantees whatsoever and might change functionality any time. 6 make no stability guarantees whatsoever and might change functionality any time.
7 7
8 ## How to use ## 8 ## How to use ##
9 9
10 ### Running the test server ### 10 ### Running the test server ###
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 No processing is performed beyond inserting localized strings and resolving 243 No processing is performed beyond inserting localized strings and resolving
244 links to pages and images. This format is mainly meant for legacy content. 244 links to pages and images. This format is mainly meant for legacy content.
245 The syntax for localizable strings documented above can be used as with 245 The syntax for localizable strings documented above can be used as with
246 Markdown. 246 Markdown.
247 247
248 #### Jinja2 format (tmpl) #### 248 #### Jinja2 format (tmpl) ####
249 249
250 Complicated pages can be defined using the 250 Complicated pages can be defined using the
251 [Jinja2 template format](http://jinja.pocoo.org/docs/templates/). Automatic 251 [Jinja2 template format](http://jinja.pocoo.org/docs/templates/). Automatic
252 escaping is active so by default values inserted into the page cannot contain 252 escaping is active so by default values inserted into the page cannot contain
253 any HTML code. Any content between `<head>` and `</head>` tags will be inserted 253 any HTML code.
254 into the head of the generated web page, everything else defined the content of 254
255 the page. 255 For Jinja2 pages that make use of the `{% extends ... %}` tag, template
256 inheritance is left to Jinja2. It is expected you will populate blocks like
257 `body` and `head` manually from those pages and have the corresponding blocks in
258 the parent template.
259
260 If a Jinja2 page does not contain an `{% extends ... %}` tag however the CMS
261 will take care of template inheritance as with the other formats. The template
262 as specified in the `template` option will be used by the CMS. Anything between
263 the `<head>` and `</head>` tags will be inserted into a `head` variable, the
264 rest into a `body` variable.
265
266 _Note: if you do not use the {% extends ... %} tag the parent template will not
267 have access to any of the page's state. Blocks, variables etc defined in the
268 page will not be available for use from the template._
269
270 If you would like your template to support both Jinja2 and standard template
271 inheritance it is recommended to follow this pattern:
272
273 ...
274 {% block head %}
275 {% head|safe %}
276 {% endblock %}
277 ...
278 {% block body %}
279 {% body|safe %}
280 {% endblock %}
256 281
257 The following variables can be used: 282 The following variables can be used:
258 283
259 * `page`: The page name 284 * `page`: The page name
260 * `config`: Contents of the `settings.ini` file in this repository (a 285 * `config`: Contents of the `settings.ini` file in this repository (a
261 [configparser object](http://docs.python.org/2/library/configparser.html)) 286 [configparser object](http://docs.python.org/2/library/configparser.html))
262 * `locale`: Locale code of the page language 287 * `locale`: Locale code of the page language
263 * `available_locales`: Locale codes of all languages available for this page 288 * `available_locales`: Locale codes of all languages available for this page
264 289
265 Following custom filters can be used: 290 Following custom filters can be used:
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 filter is invoked. For more information on Jinja2 filters see 339 filter is invoked. For more information on Jinja2 filters see
315 [official documentation](http://jinja.pocoo.org/docs/dev/api/#writing-filters). 340 [official documentation](http://jinja.pocoo.org/docs/dev/api/#writing-filters).
316 341
317 ### Custom functions and variables ### 342 ### Custom functions and variables ###
318 343
319 The `globals` directory can define custom Jinja2 globals which will be available 344 The `globals` directory can define custom Jinja2 globals which will be available
320 in all Jinja2 templates. Typically, this is used for custom functions. The file 345 in all Jinja2 templates. Typically, this is used for custom functions. The file
321 name should match the name of the function or variable to be defined, and export 346 name should match the name of the function or variable to be defined, and export
322 a variable with that name. E.g. `globals/myfunction.py` can define a function 347 a variable with that name. E.g. `globals/myfunction.py` can define a function
323 called `myfunction` that will become available to all Jinja2 templates. 348 called `myfunction` that will become available to all Jinja2 templates.
OLDNEW
« no previous file with comments | « no previous file | cms/converters.py » ('j') | cms/converters.py » ('J')

Powered by Google App Engine
This is Rietveld