Add another img
Hi everyone. I want to change the logo from the basic example but I can't get it right, It looks empty without any image.
This is my syntax for adding a new image, I have it in a folder and at the same folder but I can't get it right and I don't know why.
img(style="width:400px; display:block; margin:0 auto;" src="{{ img }}") img(style="width:400px; display:block; margin:0 auto;" src="/static/avocado.png") img(style="width:400px; display:block; margin:0 auto;" src="/static/avocado.jpg") img(style="width:400px; display:block; margin:0 auto;" src="./avocado.png") img(style="width:400px; display:block; margin:0 auto;" src="./avocado.jpg")
None of them above is showing the image.
Thank you a lot.
Looking at the generated html of the basic example, the absolute file path is used. I guess you can use python to join the relative path with the current working directory to get the absolute path and inject the path as a variable into pug. I was not able to use relative paths, only absolute paths.
Support for relative paths or an example showing how that can be done would be great!
The pug template refers to the GLOBALS variable. One option is adding the image path:
import pdf_reports
pdf_reports.GLOBALS["avocado"] = "/path/to/avocado.png"
Then modify the pug template:
img(style="width:200px; display:block; margin:0 auto;"
src="file:///{{ avocado }}")
PDF output:

A related question: attribute interpolation doesn't seem to work with pug_to_html. I have a list of images that I want to render with
each fpath in img_files
img(src=fpath)
where img_files is a list containing image paths ['file:///{{img1}}', 'file:///{{img2}}' ... ]. These paths have already been added to pdf_reports.GLOBALS. @veghp Do you have a solution to this? Thanks a lot.
Where did you define img_files?
This works for me:
pdf_reports.GLOBALS["img_files"] = ["file:///path/to/avocado.png", "file:///path/to/screenshot.png"]
Pug template:
each fpath in img_files
img(style="width:200px; display:block; margin:0 auto;"
src=fpath)

I defined img_files in another Python script and passed it to pug_to_html. It works now, thank you so much! I stored the file paths as separate keys in GLOBALS, which was why it didn't work.
Great, I'm glad it works now!