# Isset or similar function for index

**URL:** <https://discourse.gohugo.io/t/isset-or-similar-function-for-index/25026>\
**Category:** feature\
**Created:** [April 25, 2020, 11:29pm UTC](https://discourse.gohugo.io/t/isset-or-similar-function-for-index/25026 "2020-04-25T23:29:35Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![b\_rad](https://avatars.discourse-cdn.com/v4/letter/b/b2d939/32.png) [@b\_rad](https://discourse.gohugo.io/u/b_rad)\
**Post date:** [April 25, 2020, 11:29pm UTC](https://discourse.gohugo.io/t/isset-or-similar-function-for-index/25026/1 "2020-04-25T23:29:35Z")

</div>

Hello, I am not able to use `isset` on `.Site.Data` in the following partial:

```auto
{{$scratch := newScratch}}
{{$arguments := dict "dot" . "scratch" $scratch}}
{{block "fields" $arguments}}
	{{$parent := .dot.Parent}}
	{{with $parent}}
		{{if not .IsHome}}
			{{$arguments := dict "dot" . "scratch" $.scratch}}
			{{template "fields" $arguments}}
		{{end}}
	{{end}}
	{{$field := .dot.Render "_view/field" | string | slice}}
	{{.scratch.Add "fields" $field}}
{{end}}
{{$fields := $scratch.Get "fields"}}
{{return index .Site.Data $fields}}

```

The `.Render` element creates a slice of the path based on file name. This works if I use a slice that exists, for example this will look for a file in `data/wiki/hugo.yml` and works as long as a data file exists there:

```auto
{{$fields := slice "wiki" "hugo"}}
{{index .Site.Data $fields}}

```

However, because many of the pages don’t have data files it gives me an error:

```auto
hugo_1 | ERROR 2020/04/25 23:18:25 Failed to render pages: render of "page" failed: execute of template failed: template: wiki/single.html:2:3: executing "main" at <partial "data" .>: error calling partial: "/site/themes/test/layouts/partials/data.html:15:2": execute of template failed: template: partials/data.html:15:2: executing "partials/data.html" at <index .Site.Data $fields>: error calling index: index of nil pointer

```

`isset` says it works with an index, but I can’t figure out how to get it to work. Ideally Hugo would automatically have a page variable for a data file in a data folder and file with identical names. I’m not opposed to using front-matter params either, but the challenge is that if someone adds metadata to a page that I haven’t created a specific template for like so:

```auto
{{range $key, $value := .Params}}
{{if eq $key "test"}}
<span class="{{$key}}">{{$value}}</span>
{{end}}
<details>
<li>{{$key}}: {{$value}}</li>
</details>
{{end}}

```

The issue with this, is that there are page elements such as `title`, `categories` etc that are listed in the `.Params` and it seems like it can be hard to predict these.

---

<div class="post-metadata">

**Author:** ![pointyfar](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/pointyfar/32/5797_2.png) [@pointyfar](https://discourse.gohugo.io/u/pointyfar)\
**Post date:** [April 26, 2020, 3:49am UTC](https://discourse.gohugo.io/t/isset-or-similar-function-for-index/25026/2 "2020-04-26T03:49:06Z")

</div>

Hi there,

It’s easier to help you if we had a repo we can test instead of trying to recreate your setup. Have a read about [Requesting Help](https://discourse.gohugo.io/t/requesting-help/9132) .
