# Can't evaluate field \<field\> in type interface {} from a shortcode

**URL:** <https://discourse.gohugo.io/t/cant-evaluate-field-field-in-type-interface-from-a-shortcode/43933>\
**Category:** support\
**Created:** [April 16, 2023, 4:12pm UTC](https://discourse.gohugo.io/t/cant-evaluate-field-field-in-type-interface-from-a-shortcode/43933 "2023-04-16T16:12:35Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pi\_Home\_Server](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/pi_home_server/32/19259_2.png) [@Pi\_Home\_Server](https://discourse.gohugo.io/u/Pi_Home_Server)\
**Post date:** [April 16, 2023, 4:12pm UTC](https://discourse.gohugo.io/t/cant-evaluate-field-field-in-type-interface-from-a-shortcode/43933/1 "2023-04-16T16:12:35Z")

</div>

I currently have a basic post with the following expected behavior : use a parameter called reference to make the shortcode load dynamically the information from a yaml file in the data/post folder

```auto
---
title: 'title'
draft: true
featured: false
author: 'Chris'
reference: "002"
---
{{< conclusion >}}

```

The shortcode called _conclusion_ :

```auto
{{ $data := index .Site.Data.post (.Page.Params.Get "reference") }}
{{ with $data.conclusion }}
<div style="">
  <p>{{ .text }}</p>
</div>
{{ end }}

```

And a “data” file called \*002.yml’ in the data/post folder :

```auto
conclusion:
  - text: "bla bla"
  - rate: 18

```

Unfortunatly i can’t access the _text_ part of the conclusion and can’t figure out why :

```auto
execute of template failed: template: shortcodes/conclusion.html:4:8: executing "shortcodes/conclusion.html" at <.text>: can't evaluate field text in type []interface {}

```

The content of $data is correct if i print it

---

<div class="post-metadata">

**Author:** ![jmooring](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/jmooring/32/4214_2.png) [@jmooring](https://discourse.gohugo.io/u/jmooring)\
**Post date:** [April 16, 2023, 4:22pm UTC](https://discourse.gohugo.io/t/cant-evaluate-field-field-in-type-interface-from-a-shortcode/43933/2 "2023-04-16T16:22:33Z")

</div>

No:

```auto
{{ $data := index .Site.Data.post (.Page.Params.Get "reference") }}

```

Yes:

```auto
{{ $data := index .Site.Data.post .Page.Params.reference }}

```

Use the `.Get` method to “get” parameters passed to the shortcode, not to to “get” other things.

---

<div class="post-metadata">

**Author:** ![Pi\_Home\_Server](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/pi_home_server/32/19259_2.png) [@Pi\_Home\_Server](https://discourse.gohugo.io/u/Pi_Home_Server)\
**Post date:** [April 16, 2023, 6:28pm UTC](https://discourse.gohugo.io/t/cant-evaluate-field-field-in-type-interface-from-a-shortcode/43933/3 "2023-04-16T18:28:39Z")

</div>

Thanks for the improvement  
The first line of the shortcode is now :

```auto
{{ $data := index .Site.Data.post .Page.Params.reference }}

```

However the error is still here

---

<div class="post-metadata">

**Author:** ![jmooring](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/jmooring/32/4214_2.png) [@jmooring](https://discourse.gohugo.io/u/jmooring)\
**Post date:** [April 16, 2023, 6:56pm UTC](https://discourse.gohugo.io/t/cant-evaluate-field-field-in-type-interface-from-a-shortcode/43933/4 "2023-04-16T18:56:09Z")

</div>

I didn’t notice that your data file was malformed.

With this markdown:

```plaintext
+++
title = 'Post 1'
date = 2023-04-16T11:51:23-07:00
draft = false
reference = '002'
+++

{{< conclusion >}}

```

And this shortcode:

```plaintext
{{ $data := index .Site.Data.post .Page.Params.reference }}
{{ with $data.conclusion }}
  <div style="">
    <p>{{ .text }}</p>
  </div>
{{ end }}

```

And this data file:

```plaintext
conclusion:
  text: "bla bla"
  rate: 18

```

I get “bla bla”

---

<div class="post-metadata">

**Author:** ![Pi\_Home\_Server](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/pi_home_server/32/19259_2.png) [@Pi\_Home\_Server](https://discourse.gohugo.io/u/Pi_Home_Server)\
**Post date:** [April 16, 2023, 7:10pm UTC](https://discourse.gohugo.io/t/cant-evaluate-field-field-in-type-interface-from-a-shortcode/43933/5 "2023-04-16T19:10:05Z")

</div>

Bingo ! The array was not the structure i wanted ! Thank you for your time and help !

---

<div class="post-metadata">

**Author:** ![system](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/system/32/1_2.png) [@system](https://discourse.gohugo.io/u/system)\
**Post date:** [April 18, 2023, 7:10pm UTC](https://discourse.gohugo.io/t/cant-evaluate-field-field-in-type-interface-from-a-shortcode/43933/6 "2023-04-18T19:10:06Z")

</div>

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