Attempting to make embeded pdf shortcode

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

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

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.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.