# Issues using APPLY with my partial

**URL:** <https://discourse.gohugo.io/t/issues-using-apply-with-my-partial/35427>\
**Category:** support\
**Created:** [November 3, 2021, 8:23pm UTC](https://discourse.gohugo.io/t/issues-using-apply-with-my-partial/35427 "2021-11-03T20:23:15Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![solus](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/solus/32/15500_2.png) [@solus](https://discourse.gohugo.io/u/solus)\
**Post date:** [November 3, 2021, 8:23pm UTC](https://discourse.gohugo.io/t/issues-using-apply-with-my-partial/35427/1 "2021-11-03T20:23:15Z")

</div>

I have a shortcode that accepts a variable number of distinct parameters that are formatted and sorted. When sorted, certain items are placed at the front in a particular order, and all others are added to the end in the order they were received.

I have this working with the following code. Duplicate parameters are removed by _uniq_, and the remaining parameters are pushed through a partial that may reformat the text. The partial returns a string, and the result is appended to $keys. Finally, the _intersect_ takes $modifiers (in the order they should appear in the final results) and $keys so that a collection of matching modifiers is created in the desired order. That collection is then passed to _union_ along with $keys.

This code works:

```auto
{{- $modifiers := slice "Ctrl" "LCtrl" "RCtrl" "Alt" "LAlt" "RAlt" "Opt" "LOpt"
    "ROpt" "Shift" "LShift" "RShift" "Win" "LWin" "RWin" "Cmd" "LCmd" "RCmd" "Fn" }}

{{- $keys := (slice) }}
{{- range .Params | uniq }}
{{- $keys = $keys | append (partial "func/getKey.html" (. | safeHTML)) }}
{{- end }}

{{- $sorted := union (intersect $modifiers $keys) $keys -}}

```

Having read the docs on _apply_, I thought this code might simply things and replace the _range_ loop with a a single statement:

```auto
{{- $modifiers := slice "Ctrl" "LCtrl" "RCtrl" "Alt" "LAlt" "RAlt" "Opt" "LOpt"
     "ROpt" "Shift" "LShift" "RShift" "Win" "LWin" "RWin" "Cmd" "LCmd" "RCmd" "Fn" }}

{{- $keys := apply (.Params | uniq) "partial" "func/getKey.html" "." -}}

{{- $sorted := union (intersect $modifiers $keys) $keys -}}

```

For some reason, I receive an error with the _union_ stating that “value of type interface {} is not assignable to type string”. I have no idea what that means, and the web searches I completed turned up nothing useful.

> at \<union (intersect $modifiers $keys) $keys\>: error calling union: reflect.Set: value of type interface {} is not assignable to type string

I tried simplifying things more just to get it to compile:

```auto
{{- $sorted := apply .Params "partial" "func/getKey.html" "." -}}

```

But now I receive a different error.

> at \<apply .Params “partial” “func/getKey.html” “.”\>: error calling apply: partial that returns a value needs a non-zero argument.

Is something wrong with my partial?

Here’s a truncated version of “func/getKey.html”:

```auto
{{ $key := lower . }}
{{ if (eq $key "control") }}{{ $key = "Ctrl" }}
{{ else if (eq $key "option") }}{{ $key = "Opt" }}
{{ else if (eq $key "command") }}{{ $key = "Cmd" }}
{{ else if (eq $key "windows") }}{{ $key = "Win" }}
{{ else if (eq $key "function") }}{{ $key = "Fn" }}
{{ else if eq $key "escape" }}{{ $key = "Esc" }}
---//---
{{ else }}{{ $key = title $key }}{{ end }}
{{ return printf "%s" $key}}

```

I’m running Hugo server _ **hugo v0.85.0-724D5DB5+extended windows/amd64 BuildDate=2021-07-05T10:46:28Z VendorInfo=gohugoio** _ with the following arguments “-D --disableFastRender --bind={local IP} --baseURL={url} -p {port}” I’m going to see if a new build changes this behavior.

---

<div class="post-metadata">

**Author:** ![solus](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/solus/32/15500_2.png) [@solus](https://discourse.gohugo.io/u/solus)\
**Post date:** [November 3, 2021, 8:36pm UTC](https://discourse.gohugo.io/t/issues-using-apply-with-my-partial/35427/2 "2021-11-03T20:36:03Z")

</div>

I did discover that when calling the shortcode from markdown content files, I don’t normally need to quote alphanumeric parameters, such as `{{< foo p1 p2 p3 >}}`. However when passing and unquoted `0`, the _apply_/_partial_ call was generating the “partial that returns a value needs a non-zero argument” error. When I changed the parameter to `"0"`, that error went away. Why does this happen? Shouldn’t the unquoted `0` work? It does when I use the loop instead of _apply_.

I still have some type of issue with the _apply_ and _union_ where “value of type interface {} is not assignable to type string”.

```auto
{{- $keys := apply (.Params | uniq) "partial" "func/getKey.html" "." -}}
{{- $sorted := union (intersect $modifiers $keys) $keys -}}

```

$modifiers is a slice containing strings.  
What is the type of $keys? I assumed it would be a slice or array (still somewhat confused over the difference) and that it also contains the strings returned by the partial.

---

<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:** [November 4, 2021, 6:11am UTC](https://discourse.gohugo.io/t/issues-using-apply-with-my-partial/35427/3 "2021-11-04T06:11:42Z")

</div>

markdown

```auto
{{< foo "Option" "OPTION" "command" "CONTROL" "zebra" "APPLE" >}}

```

layouts/partials/func/getKey.html

```auto
{{ $lookup := dict
  "control" "Ctrl"
  "option" "Opt"
  "command" "Cmd"
  "windows" "Win"
  "function" "Fn"
  "escape" "Esc"
}}
{{ return or (index $lookup .) (title .) }}

```

layouts/shortcodes/foo.html

```auto
{{ $modifiers := slice
  "Ctrl" "LCtrl" "RCtrl" "Alt" "LAlt" "RAlt" "Opt" "LOpt" "ROpt" "Shift"
  "LShift" "RShift" "Win" "LWin" "RWin" "Cmd" "LCmd" "RCmd" "Fn"
}}
{{ $params := apply .Params "lower" "." | uniq | sort }}
{{ $keys := apply $params "partial" "func/getKey.html" "." }}
{{ $sorted := union (intersect $modifiers $keys) $keys }}
{{ delimit $sorted ", " }}

```

output

```nohighlight
Ctrl, Opt, Cmd, Apple, Zebra

```

---

<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:** [November 4, 2021, 6:22am UTC](https://discourse.gohugo.io/t/issues-using-apply-with-my-partial/35427/4 "2021-11-04T06:22:43Z")

</div>

> [@solus](#):
>
> However when passing and unquoted `0` , the _apply_ / _partial_ call was generating the “partial that returns a value needs a non-zero argument” error. When I changed the parameter to `"0"` , that error went away. Why does this happen? Shouldn’t the unquoted `0` work?

That’s just a limitation of the `return` function.

layouts/partials/render-value.html

```auto
{{ . }}

```

layouts/partials/return-value.html

```auto
{{ return . }}

```

partial calls

```auto
{{ partial "render-value.html" 0 }} --> 0
{{ partial "return-value.html" 0 }} --> ERROR partial that returns a value needs a non-zero argument

```
