Skip to content

How to add custom tags to latest Ghostwriter 4.2.1 to replace Jinja tag with an image of a chart? #476

Closed Answered by ArgentEnergy
ArgentEnergy asked this question in Q&A
Discussion options

You must be logged in to vote

I figured it out. Took multiple attempts and figuring out where to place the code.

ExportDocxBase - Added custom code in the run method before the DocxTemplate render call to create the bar charts. The custom code creates a new subdocument using the word_doc variable in the ExportDocxBase class and I use my existing code to add the image to the subdocument.

sd = word_doc.new_subdoc()
sd.add_picture(filepath, width=width, height=height)
...
# I then add the bar chart custom tag to the docx_context with the subdocument as the value before the render and save is called on the template
docx_context["project"][tag] = sd

ExportReportBase - Has the custom bar chart tags in the map_rich_texts method

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by ArgentEnergy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant