# Best method to collect all sources/external URLs

**URL:** https://discourse.gohugo.io/t/best-method-to-collect-all-sources-external-urls/44183
**Category:** support
**Created:** [May 2, 2023, 1:44pm UTC](https://discourse.gohugo.io/t/best-method-to-collect-all-sources-external-urls/44183 "2023-05-02T13:44:12Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![Tom\_Durand](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/tom_durand/32/14460_2.png) [@Tom\_Durand](https://discourse.gohugo.io/u/Tom_Durand)
#### Post date: [May 2, 2023, 1:44pm UTC](https://discourse.gohugo.io/t/best-method-to-collect-all-sources-external-urls/44183/1 "2023-05-02T13:44:12Z")

</div>

Hi,

> {{ .Page.Scratch.Add “all\_sources” (slice $.Text $destination) }}

is returning returning me what seems to be a slice with only one string, containing all links, with .Text and $destination.  
Separated by space, or not, depends. It’s a mess.  
I expected a map or slice of strings, which I could use `delimit` on.  
I read the docu and don’t understand.  
The result of `{{ delimit (.Page.Scratch.Get "all_sources") " "}} ` is

```auto
error calling delimit: can’t iterate over <nil> failed to render pages: can’t iterate over <nil> 

```

---

<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: [May 2, 2023, 1:51pm UTC](https://discourse.gohugo.io/t/best-method-to-collect-all-sources-external-urls/44183/2 "2023-05-02T13:51:25Z")

</div>

> [@Tom\_Durand](#):
>
> `can’t iterate over <nil>`

One or more of the pages rendered with this code does not have matching Scratch. You need to code defensively.

---

<div class="post-metadata">

### Author: ![Tom\_Durand](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/tom_durand/32/14460_2.png) [@Tom\_Durand](https://discourse.gohugo.io/u/Tom_Durand)
#### Post date: [May 2, 2023, 1:56pm UTC](https://discourse.gohugo.io/t/best-method-to-collect-all-sources-external-urls/44183/3 "2023-05-02T13:56:50Z")

</div>

Ah… Ok  
Still, more documentation and examples of use cases wouldn’t hurt.  
One more question : why does the result of this:

```auto
{{with (.Page.Scratch.Get "all_sources")}}
	{{ delimit . "<p>"}}
{{ end }}

```

(with the command `hugo server`) changes when it reloads, when I save the text editor on such or such file ? It appears as it should with when saving `render-link.html` but is empty/outputs nothing when saving on `content-after.html`.  
But that difference doesn’t happen with .Store instead of .Scratch.  
Is this a feature or a bug ?  
And I don’t understand what .Get is returning. I would expect a slice of slices,  
but it’s not the case because `{{range . }}<p>{{ delimit . " "}}{{end}}` is returning me gibberish numbers like `104 116 116 112 115 58 47 47 119 119 119 46 103 105 103 97 108 114 101 115 101 97 114 99 104 46 99 111 109 47 117 107 47 112 117 98 108`

None of the entries were numbers or close, it shouldn’t happen…  
Damn weakly-typed languages.

---

<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: [May 2, 2023, 2:09pm UTC](https://discourse.gohugo.io/t/best-method-to-collect-all-sources-external-urls/44183/4 "2023-05-02T14:09:33Z")

</div>

`.Get` returns what you `.Set`. This is a “you” problem, not a Hugo problem.

---

<div class="post-metadata">

### Author: ![Tom\_Durand](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/tom_durand/32/14460_2.png) [@Tom\_Durand](https://discourse.gohugo.io/u/Tom_Durand)
#### Post date: [May 2, 2023, 2:11pm UTC](https://discourse.gohugo.io/t/best-method-to-collect-all-sources-external-urls/44183/5 "2023-05-02T14:11:19Z")

</div>

so `{{ .Page.Store.Add "all_sources" (slice $.Text $destination) }}` followed by `{{{ .Page.Get "all_sources"}}` should return a slice of slices, right ? .Text being a string and $destination too.

---

<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: [May 2, 2023, 4:14pm UTC](https://discourse.gohugo.io/t/best-method-to-collect-all-sources-external-urls/44183/6 "2023-05-02T16:14:26Z")

</div>

> [@Tom\_Durand](#):
>
> `.Add` … should return a slice of slices, right ?

`.Add` doesn’t return anything. It adds _something_ to an existing _something_ that you initialized with `.Set.`

```auto
{{ .Page.Store.Set "foo" (slice "aaa" "bbb") }}

{{ .Page.Store.Get "foo" }} --> [aaa bbb] 

{{ .Page.Store.Add "foo" (slice "ccc" "ddd") }}

{{ .Page.Store.Get "foo" }} --> [aaa bbb ccc ddd]

```

[https://gohugo.io/functions/scratch/#add](https://gohugo.io/functions/scratch/#add)

> If the first `Add` for a key is an array or slice, the following adds will be appended to that list.

---

<div class="post-metadata">

### Author: ![Tom\_Durand](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/tom_durand/32/14460_2.png) [@Tom\_Durand](https://discourse.gohugo.io/u/Tom_Durand)
#### Post date: [May 2, 2023, 4:17pm UTC](https://discourse.gohugo.io/t/best-method-to-collect-all-sources-external-urls/44183/7 "2023-05-02T16:17:06Z")

</div>

> [@jmooring](#):
>
> > [@Tom\_Durand](#):
> >
> > `.Add` … should return a slice of slices, right ?

I meant .Get, sorry.  
Yes I read that sentence but didn’t understand. Now I do.  
How can I get the object to be a slice of slices instead ?  
Like [[aaa bbbb] [cccc ddd]]  
also I noticed that I didn’t initiliaze the object, yet it doesn’t seem to matter. Or perhaps it caused the erratic behavior I described?

---

<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: [May 2, 2023, 4:23pm UTC](https://discourse.gohugo.io/t/best-method-to-collect-all-sources-external-urls/44183/8 "2023-05-02T16:23:02Z")

</div>

> [@Tom\_Durand](#):
>
> yet it doesn’t seem to matter.

Yes, it does.

> [@Tom\_Durand](#):
>
> How can I get the object to be a slice of slices instead

If you want it to be a slice of slices, you need to give it a slice of slices.

```plaintext
{{ .Page.Store.Set "foo" (slice (slice "aaa" "bbb") (slice "ccc" "ddd")) }}
{{ .Page.Store.Get "foo" }} --> [[aaa bbb] [ccc ddd]]

```

---

<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: [May 4, 2023, 4:23pm UTC](https://discourse.gohugo.io/t/best-method-to-collect-all-sources-external-urls/44183/9 "2023-05-04T16:23:59Z")

</div>

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