File tree 1 file changed +17
-8
lines changed 1 file changed +17
-8
lines changed Original file line number Diff line number Diff line change @@ -587,17 +587,26 @@ When combined with ``scoped``, the ``required`` modifier must be placed
587
587
Template Objects
588
588
~~~~~~~~~~~~~~~~
589
589
590
- .. versionchanged :: 2.4
590
+ ``extends ``, ``include ``, and ``import `` can take a template object
591
+ instead of the name of a template to load. This could be useful in some
592
+ advanced situations, since you can use Python code to load a template
593
+ first and pass it in to ``render ``.
594
+
595
+ .. code-block :: python
596
+
597
+ if debug_mode:
598
+ layout = env.get_template(" debug_layout.html" )
599
+ else :
600
+ layout = env.get_template(" layout.html" )
591
601
592
- If a template object was passed in the template context, you can
593
- extend from that object as well. Assuming the calling code passes
594
- a layout template as `layout_template ` to the environment, this
595
- code works::
602
+ user_detail = env.get_template(" user/detail.html" , layout = layout)
603
+
604
+ .. code-block :: jinja
596
605
597
- {% extends layout_template %}
606
+ {% extends layout %}
598
607
599
- Previously, the ` layout_template ` variable had to be a string with
600
- the layout template's filename for this to work .
608
+ Note how `` extends `` is passed the variable with the template object
609
+ that was passed to `` render ``, instead of a string .
601
610
602
611
603
612
HTML Escaping
You can’t perform that action at this time.
0 commit comments