# Initialize empty variable/array for resources

**URL:** <https://discourse.gohugo.io/t/initialize-empty-variable-array-for-resources/27816>\
**Category:** support\
**Created:** [August 25, 2020, 8:57am UTC](https://discourse.gohugo.io/t/initialize-empty-variable-array-for-resources/27816 "2020-08-25T08:57:45Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![martins](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/martins/32/12229_2.png) [@martins](https://discourse.gohugo.io/u/martins)\
**Post date:** [August 25, 2020, 8:57am UTC](https://discourse.gohugo.io/t/initialize-empty-variable-array-for-resources/27816/1 "2020-08-25T08:57:45Z")

</div>

Hi,  
I’m creating an assets bundle. I have multiple folders with sass files (“components”, “forms”, “buttons” etc). I’m iterating through all those folders and adding files from each folder to “main.scss” file. Code below works but I would like to remove the need to Initialize $style variable with a resource.

```
{{ $style := resources.Get "scss/main.scss" }}

```

I would like to initialize $style as an empty array to which I later add all those files.

Something like this (it does not work)

```
{{ $style := [] }}

```

My current code:

```
{{ $style := resources.Get "scss/main.scss" }}
{{ $components := resources.Match "scss/**/*.scss" }}
{{ range $components }}
    {{ $style = slice $style . | resources.Concat .Name }}
{{ end }}
{{ $style = slice $style | resources.Concat "main.scss" | toCSS | minify | fingerprint }}
<link rel="stylesheet" href="{{ $style.Permalink }}">
```

---

<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:** [August 25, 2020, 9:28am UTC](https://discourse.gohugo.io/t/initialize-empty-variable-array-for-resources/27816/2 "2020-08-25T09:28:43Z")

</div>

> [@martins](#):
>
> `{{ $style := [] }}`

Try `{{ $style := slice }}`

---

<div class="post-metadata">

**Author:** ![martins](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/martins/32/12229_2.png) [@martins](https://discourse.gohugo.io/u/martins)\
**Post date:** [August 25, 2020, 9:33am UTC](https://discourse.gohugo.io/t/initialize-empty-variable-array-for-resources/27816/3 "2020-08-25T09:33:36Z")

</div>

> [@pointyfar](#):
>
> Try `{{ $style := slice }}`

Unfortunately it does not work. It gives this error:

```
at <resources.Concat>: error calling Concat: slice []interface {} not supported in concat

```

---

<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:** [August 25, 2020, 9:41am UTC](https://discourse.gohugo.io/t/initialize-empty-variable-array-for-resources/27816/4 "2020-08-25T09:41:39Z")

</div>

You will have to modify the rest of your code as well, since `$style` is now an array.

Something like

```auto
{{ $stylearr := slice }}

{{ range $components }}
  {{ $stylearr = $stylearr | append . }}
{{ end }}

{{ $generatedstyle := $stylearr | resources.Concat "main.scss" | toCSS $options | minify | fingerprint }}
{{ $generatedstyle.Permalink }}

```

---

<div class="post-metadata">

**Author:** ![martins](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/martins/32/12229_2.png) [@martins](https://discourse.gohugo.io/u/martins)\
**Post date:** [August 25, 2020, 9:49am UTC](https://discourse.gohugo.io/t/initialize-empty-variable-array-for-resources/27816/5 "2020-08-25T09:49:53Z")

</div>

> [@pointyfar](#):
>
> You will have to modify the rest of your code as well, since `$style` is now an array.

**It worked and this makes so much sense now.**

Thanks and have a good one!

---

<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:** [August 27, 2020, 9:49am UTC](https://discourse.gohugo.io/t/initialize-empty-variable-array-for-resources/27816/6 "2020-08-27T09:49:58Z")

</div>

Closed on August 27, 2020, 9:49am UTC

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