# Eval function

**URL:** <https://discourse.gohugo.io/t/eval-function/32148>\
**Category:** feature\
**Created:** [April 3, 2021, 1:17pm UTC](https://discourse.gohugo.io/t/eval-function/32148 "2021-04-03T13:17:27Z")\
**Posts on this page:** 1\
**Showing post:** 5

<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 3, 2021, 4:45pm UTC](https://discourse.gohugo.io/t/eval-function/32148/5 "2021-04-03T16:45:32Z")

</div>

Thanks. Works great. Revised code:

```auto
{{ $s := slice "add 5 1" "sub 6 2" "mul 7 3" "div 8 4" }}
{{ range $s }}
  {{ $f := printf "%s.txt" (. | md5) }}
  {{ $r := printf "{{ %s }}" . | resources.FromString $f }}
  {{ $r = $r | resources.ExecuteAsTemplate $f . }}
  {{ printf "<pre>%s = %s</pre>" . $r.Content | safeHTML }}
{{ end }}

```

Note that `resources.FromString` does not overwrite an existing file when ranging through the slice of commands or between rebuilds when running `hugo server`. That’s why I initially used `now.UnixNano` for the temporary file name.

When we use a hash value (`md5`) for the temporary file name, the code above does not do what we think it does when our slice of commands contains duplicate items. For example:

```auto
{{ $s := slice "add 5 1" "add 5 1" }}

```

When processing the second item, `resources.ExecuteAsTemplate` uses the resource created for the first item. But that’s OK because the expected result is the same.

Thank you very much for your help.

---

_[View the full topic](https://discourse.gohugo.io/t/eval-function/32148)._
