Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add another img #12

Open
davidpatalejos opened this issue Jul 8, 2020 · 6 comments
Open

Add another img #12

davidpatalejos opened this issue Jul 8, 2020 · 6 comments
Assignees

Comments

@davidpatalejos
Copy link

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.

@bacox
Copy link

bacox commented Jul 15, 2020

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!

@veghp veghp self-assigned this Sep 12, 2020
@veghp
Copy link
Member

veghp commented Sep 12, 2020

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:
screenshot

@Theophylline
Copy link

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.

@veghp
Copy link
Member

veghp commented Oct 28, 2020

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)

Screenshot2

@Theophylline
Copy link

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.

@veghp
Copy link
Member

veghp commented Oct 28, 2020

Great, I'm glad it works now!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants