# Attach specific posts to a post

**URL:** <https://discourse.gohugo.io/t/attach-specific-posts-to-a-post/11533>\
**Category:** support\
**Created:** [April 14, 2018, 11:54am UTC](https://discourse.gohugo.io/t/attach-specific-posts-to-a-post/11533 "2018-04-14T11:54:35Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![olafghanizadeh](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/olafghanizadeh/32/4494_2.png) [@olafghanizadeh](https://discourse.gohugo.io/u/olafghanizadeh)\
**Post date:** [April 14, 2018, 11:54am UTC](https://discourse.gohugo.io/t/attach-specific-posts-to-a-post/11533/1 "2018-04-14T11:54:35Z")

</div>

Is there a way to attach/embed specific posts in Hugo?

I have a reviews section and a products section. In my reviews I would like to attach/embed the products and display their content and metadata. I’ve solved this in Wordpress in Advanced Custom Fields, is there a way to do it with Hugo?

Could I write a shortcode and make use of the relref-funcionality?

---

<div class="post-metadata">

**Author:** ![Leo\_Merkel](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/leo_merkel/32/3321_2.png) [@Leo\_Merkel](https://discourse.gohugo.io/u/Leo_Merkel)\
**Post date:** [April 14, 2018, 12:13pm UTC](https://discourse.gohugo.io/t/attach-specific-posts-to-a-post/11533/2 "2018-04-14T12:13:48Z")

</div>

In the docs: [https://gohugo.io/content-management/page-bundles/#readout](https://gohugo.io/content-management/page-bundles/#readout)

Is that what you mean?

---

<div class="post-metadata">

**Author:** ![regis](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/regis/32/4958_2.png) [@regis](https://discourse.gohugo.io/u/regis)\
**Post date:** [April 14, 2018, 1:33pm UTC](https://discourse.gohugo.io/t/attach-specific-posts-to-a-post/11533/3 "2018-04-14T13:33:40Z")

</div>

If your products are regular pages which have their own pages on the site, then you should look toward [Related Content](https://gohugo.io/content-management/related/#readout).

I wrote a piece about how this feature can help you achieve what you want:

> **[Better Relationships in Hugo, with Hugo's Related Content | Regis Philibert](https://regisphilibert.com/blog/2018/04/hugo-optmized-relashionships-with-related-content/)**
>
> By using Hugo's Related Content to manage your relationships, you could reduce your build time by 70%! In this article, we see how easy it is to implement Hugo's new Related Content feature on an existing project and how it will forever optimize the...

---

<div class="post-metadata">

**Author:** ![alexandros](https://avatars.discourse-cdn.com/v4/letter/a/ecc23a/32.png) [@alexandros](https://discourse.gohugo.io/u/alexandros)\
**Post date:** [April 14, 2018, 2:41pm UTC](https://discourse.gohugo.io/t/attach-specific-posts-to-a-post/11533/4 "2018-04-14T14:41:23Z")

</div>

Also you can use .GetPage

> **[.GetPage](https://gohugo.io/functions/getpage/#readout)**
>
> Gets a \`Page\` of a given \`path\`.

---

<div class="post-metadata">

**Author:** ![olafghanizadeh](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/olafghanizadeh/32/4494_2.png) [@olafghanizadeh](https://discourse.gohugo.io/u/olafghanizadeh)\
**Post date:** [April 15, 2018, 10:42am UTC](https://discourse.gohugo.io/t/attach-specific-posts-to-a-post/11533/5 "2018-04-15T10:42:20Z")

</div>

Yeah. This works. Any idea how I would implement with a shortcode?

I tried this but I couldn’t get it to work.

Shortcode:  
`{{< shortcode path-to-post >}}`

Template (shortcode.html):

```
{{ with .Site.GetPage "page" "section" "{{ .Get 0}}.md" }}
{{ .Title }}
    {{.Summary}}
{{ end }}
```

---

<div class="post-metadata">

**Author:** ![cmal](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/cmal/32/5324_2.png) [@cmal](https://discourse.gohugo.io/u/cmal)\
**Post date:** [April 15, 2018, 10:52am UTC](https://discourse.gohugo.io/t/attach-specific-posts-to-a-post/11533/6 "2018-04-15T10:52:07Z")

</div>

> [@olafghanizadeh](#):
>
> I tried this but I couldn’t get it to work.

When something doesn’t work, it’s always nice to show precisely what kind of data you fed it, what what it output, or what error it produced. This makes it way easier to get some help 🙂

I can already tell you that as far as I know nested brackets is not possible in go templates. The brackets delimit what’s compiled from what’s left intact in the output. So here you’re already in a go part of your template, you can’t introduce `{{ .Get 0}}` like this.

For this kind of purpose we usually use [printf](https://gohugo.io/functions/printf/) like so:

```auto
printf "%s.md" (.Get 0)

```

You may need to put additional parenthesis around the whole expression so that it’s considered as one argument by the `GetPage` function.

---

<div class="post-metadata">

**Author:** ![olafghanizadeh](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/olafghanizadeh/32/4494_2.png) [@olafghanizadeh](https://discourse.gohugo.io/u/olafghanizadeh)\
**Post date:** [April 15, 2018, 12:24pm UTC](https://discourse.gohugo.io/t/attach-specific-posts-to-a-post/11533/7 "2018-04-15T12:24:05Z")

</div>

I think we are on the right track here, but trying to implement it like this:

`{{ with .Site.GetPage "page" "section" "(printf "%s.md" (.Get 0))" }}`

I get:  
`unexpected "%" in operand`

---

<div class="post-metadata">

**Author:** ![kaushalmodi](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/kaushalmodi/32/2567_2.png) [@kaushalmodi](https://discourse.gohugo.io/u/kaushalmodi)\
**Post date:** [April 15, 2018, 12:34pm UTC](https://discourse.gohugo.io/t/attach-specific-posts-to-a-post/11533/8 "2018-04-15T12:34:18Z")

</div>

> [@olafghanizadeh](#):
>
> “(printf “%s.md” (.Get 0))”

`printf` returns a string, so you don’t double-quote that `printf` expression.

Also, as that code is within a shortcode, you would need to use the “root context” `$`… So `$.Site. ..` instead of just `.Site. ..`.

… and specifying the `.md` extension in the `.GetPage` expression is optional.

---

<div class="post-metadata">

**Author:** ![olafghanizadeh](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/olafghanizadeh/32/4494_2.png) [@olafghanizadeh](https://discourse.gohugo.io/u/olafghanizadeh)\
**Post date:** [April 15, 2018, 1:42pm UTC](https://discourse.gohugo.io/t/attach-specific-posts-to-a-post/11533/9 "2018-04-15T13:42:14Z")

</div>

The double-quote was the issue.
