File tree Expand file tree Collapse file tree 3 files changed +34
-0
lines changed Expand file tree Collapse file tree 3 files changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -351,6 +351,19 @@ def render_properties(
351
351
rendered = template .render (context )
352
352
setattr (self .docx .core_properties , prop , rendered )
353
353
354
+ def render_footnotes (
355
+ self , context : Dict [str , Any ], jinja_env : Optional [Environment ] = None
356
+ ) -> None :
357
+ if jinja_env is None :
358
+ jinja_env = Environment ()
359
+
360
+ for section in self .docx .sections :
361
+ for part in section .part .package .parts :
362
+ if part .content_type == 'application/vnd.openxmlformats-officedocument.wordprocessingml.footnotes+xml' :
363
+ xml = self .patch_xml (part .blob .decode ('utf-8' ) if isinstance (part .blob , bytes ) else part .blob )
364
+ xml = self .render_xml_part (xml , part , context , jinja_env )
365
+ part ._blob = xml
366
+
354
367
def resolve_listing (self , xml ):
355
368
356
369
def resolve_text (run_properties , paragraph_properties , m ):
@@ -483,6 +496,8 @@ def render(
483
496
484
497
self .render_properties (context , jinja_env )
485
498
499
+ self .render_footnotes (context , jinja_env )
500
+
486
501
# set rendered flag
487
502
self .is_rendered = True
488
503
Original file line number Diff line number Diff line change
1
+ # -*- coding: utf-8 -*-
2
+ """
3
+ Created : 2024-09-23
4
+
5
+ @author: Bart Broere
6
+ """
7
+
8
+ from docxtpl import DocxTemplate
9
+
10
+ DEST_FILE = "output/footnotes.docx"
11
+
12
+ tpl = DocxTemplate ("templates/footnotes_tpl.docx" )
13
+
14
+ context = {
15
+ "a_jinja_variable" : "A Jinja variable!"
16
+ }
17
+
18
+ tpl .render (context )
19
+ tpl .save (DEST_FILE )
You can’t perform that action at this time.
0 commit comments