Is it possible to add partial templates into the content?

Hello,

for some pages i need the translated partial template but i dont know how i can make it working.

The problem is that i dont like to add html to the content files, so i would like to import the templates between the content sections.

Its a static page like

…content
…content
…>html for internal advertising
…content
…content

is that possible?

I’ve done this in the template, I just make an if statement that checks the page title or type based on whatever condition you want to render the partial.

Here’s an example where I render the author partial on the blog posts and another one is a loop to render all leaders in the leadership page.

<div class="content">
    <h1>{{ .Title }}</h1>

    {{ .Content }}

    {{ if isset .Params "author" }}
        {{ range .Site.Data.authors }}
            {{ $author := lower $.Params.author }}
            {{ $pageAuthor := lower .author }}
            {{ if eq $author $pageAuthor }}
                {{ partial "author" . }}
            {{ end }}
        {{ end }}
    {{ end }}

    {{ if eq .Title "Leadership"}}
        {{ range sort .Site.Data.authors "order" "asc"}}
            {{ partial "author" . }}
        {{ end }}
    {{ end }}

</div>

I’m still a hugo n00b so there might be a better way to do this but this is how I’ve accomplished it and it works.

Good luck.

Couldn’t you use a shortcode for this? https://gohugo.io/extras/shortcodes. Also, you can put the previous code in the block template, or the single layout rather than having to put that code on every post page. If there are some pages where it’s not required you could give it a front matter parameter to toggle, or just use the isset as your check.