Hi, I’ve been trying to make a shortcode to embed a pdf (my resume) on a page on my hugo site. The error I’m getting is:
execute of template failed: template: shortcodes/embed_pdf.html:15:27: executing “shortcodes/embed_pdf.html” at <.get>: can’t evaluate field get in type *hugolib.ShortcodeWithPage
the way I’m attempting to get the url is:
{{<embed_pdf file=“static/etduncan_resume_24.pdf”>}}
and the way I’m attempting to use the url to the pdf is:
< iframe id=“pdf” src=“{{.get file
}}” frameborder=“0”>
^exept no space, but wouldn’t show up without it
I hope someone can help with this, thank you!
https://gohugo.io/methods/shortcode/get/
You need to capitalize the method name and wrap the argument name in quotes:
<iframe id="pdf" src="{{ .Get "file" }}" frameborder="0">
Files placed in the static directory are copied to the public directory when you build your site, so you need to exclude “static” from the file path.
{{< embed_pdf file="/etduncan_resume_24.pdf" >}}
Finally, when posting code, configuration, or data on this forum, please wrap the text within triple backticks or use the </>
button in the menu.
```
my code
```
1 Like
iaeiou
June 18, 2024, 8:40am
3
See also this shortcode, working at least for me:
1 Like
This shortcode embeds a bunch of CSS inline. I find that irritating, because overriding these style definitions is more difficult than it needs to be.
It also uses an onload
handler instead of DOMContedLoaded
to run JavaScript. See
When building web pages, it’s important to know when to execute JavaScript. Two crucial events, DOMContentLoaded and window.onload, can help you determine this. Let’s explore the differences.
Timing DOMContentLoaded: Fires when the HTML document is...
to learn why that might not be a terrific idea.
Thank you very much for the feedback, got it working! I also had to use `` instead of quotations for the argument name.
system
Closed
June 20, 2024, 10:07pm
6
This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.