Referencing Files from within .Content

Is there a way to tell Hugo to include a file (like a partial) from within the .Content in a page? Here’s my scenario:

I have a site built and published already. I decided I wanted to embed sharing buttons on all of the pages, within the content that I reference with the {{ .Content }} in my single.html template file. The site meets my expectations already, and I just want to insert the buttons in the middle of the page content.

I tried using a reference to a partial file using {{ partial “share_buttons.html” . }} . This works very nicely for my home page content (which is held in a partial file), but does not work for the other pages at all (which invoke {{ .Content }} ). For those pages, the {{ partial “share_buttons.html” . }} simply shows up as text on the resultant web page.

I tried using an html include, which not only seems a little silly when using Hugo, but also fails to work (it shows the share buttons, but everything else is missing). (Of potential note, my content files are .html, not .md files. Not sure if that matters. I’m not actually writing markdown, and my editor color codes the html files nicely, whereas it does not color code the .md files. )

In summary, I’m looking for a way to reference common content (a file) for inclusion in all of my pages from within the {{ .Content }} portion of my pages.

Many Thanks!

Ron

Sweetness! Thank You!

As a quick summary of the solution I implemented based upon the link given above:

I had a file (sharebuttons.html) that I wanted to insert into content throughout my site. I looked for the “shortcodes” directory within the “layouts” directory. It wasn’t there, so I simply created it. I dropped my sharebuttons.html file into the new directory then went back and modified my content files with the simple line {{< sharebuttons >}} wherever I wanted the code held within sharebuttons.html to be inserted into my overall content. BOOM! It worked like a charm.

There are a ton of cool things that can be done with shortcodes, as detailed in the link above. Lots of pre-defined shortcodes that don’t need to be created. But for the most simple case, as I described above, the solution is pretty straightforward once you know where to look.

Happy shortcoding!

Best Regards,

Ron