I'm trying to use a shortcode in a .md file and get the following issue: failed to extract shortcode: template for shortcode "myshortcode" not found

Repo: GitHub - Tetizera/reddit-census-reurope: Using Hugo to create a website for the r/europe 2021 census.

I’m trying to invoke a shortcode in test.md and I get an error. If it worked, it should show a string “Hello World” on the screen.

Instead, I get: failed to extract shortcode: template for shortcode “myshortcode” not found

I tried both /layouts/myshortcode.html and /layouts/partials/myshortcode.html and even adding myshortcode.html in the layouts folder of the theme I’m using. In all three attempts hugo didn’t find the file. I searched around a bit and couldn’t find a solution to this.

To create a shortcode, place an HTML template in the layouts/shortcodes directory of your source organization.

I created layouts/shortcodes, layouts/file.html and layouts/partials and none of them work. It’s in the repo. The current one isn’t in layouts/shortcode, but I can push this change to the repo for you to see that it isn’t working even if I do this.



Move it to this structure:


Second, if you want to call shortcode template like this:

{{< myshortcode >}}
The content inside this shortcode is a shortcode
{{</ myshortcode >}}

You need to call .Inner variable inside your shortcode template:

<!-- layouts/shortcodes/myshortcode.html -->
{{ .Inner }}
<p>Hello World!</p>

Thank you! I didn’t know I had to add .Inner or any kind of snippet to the .html file.

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