Is there a way to include a .Page within a .Page?

#1

Not sure if this can be done, but it is possible to include a page within a page from two different sections?

I have:

/section-a/this-post.md

And I want to include at the end:

/section-b/different-post.md

So when I visit /section-a/this-post/ I see both posts.

I tried with shortcodes, but no dice!

0 Likes

#2

This can be done with shortcodes. What have you tried so far?

0 Likes

#3

I am doing this without shortcode. In the template I add the following:

<footer id="authorinfo">
  <div class="container">
    <div class="row">
      <div class="col-12">
        {{ with .Site.GetPage "page" "sitewide/authorfooter.md" }}
          <div id="authorfooter">
            <h3>{{ .Title }}</h3>
            {{ .Content }}
          </div>
        {{ end }}       
      </div>
    </div>
  </div>
</footer>

This would probably go well in a shortcode if you need to print it inside of a page content instead of the footer.

The files header looks like the following:

---
title: "Title"
headless: true
---

This should result in no extra page created for this.

This is a Hugo 0.35+ feature. https://gohugo.io/news/0.35-relnotes/

1 Like

#4

I tried a shortcode:

   {{ range .Site.Pages .Params.style "Jobs" }}
        {{ . }}
    {{ end }}

And it gives the following error:

executing "partials/disqus.html" at <where .Site.Pages .P...>: error calling where: regular-full isn't a field of struct type *hugolib.Page

The thing is that I want to access not just the content, but the styles and everything in that page. Not sure how to do it without going the jQuery way of reading the file itself.

My structure is:

/content/
   /features/
   subscribe.html
   some-page.html

I want to have some-page.html show, styles and all, inside subscribe.html

0 Likes

#5

Hi!

Solved it!

{{ range .Site.Pages }}
  {{ if eq .Params.style "Jobs" }}
    {{ partial "article_templates.html" . }}
  {{ end }}
{{ end }}

That can go in a shortcode and works!

Thanks Hugo!

0 Likes