# About return…

**URL:** <https://discourse.gohugo.io/t/about-return/27864>\
**Category:** support\
**Created:** [August 27, 2020, 2:31pm UTC](https://discourse.gohugo.io/t/about-return/27864 "2020-08-27T14:31:57Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![hucste](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/hucste/32/10014_2.png) [@hucste](https://discourse.gohugo.io/u/hucste)\
**Post date:** [August 27, 2020, 2:31pm UTC](https://discourse.gohugo.io/t/about-return/27864/1 "2020-08-27T14:31:57Z")

</div>

First, very good idea! 😃

I read this topic:

> [@Returning values from partials](https://discourse.gohugo.io/t/returning-values-from-partials/26944):
>
> The docs are a bit unclear to me. says: In order to return a value, a partial must include a lone return statement. A lone return statement is AFAIK: {{ return }} However the examples show {{ return $value }} (which makes more sense) The docs also say (emphasis mine): Only one return statement is allowed per partial file. This would imply that – you cannot have {{ if ... }}{{ return $this }}{{ else }}{{ return $that }}{{ end }} you cannot have multiple inline partials that ret…

But, I’ve one question:  
It’s possible to call in other partial?

* * *

By instance, with this code:

```auto
{{* partial "return-description" *}}
{{ $desc := "" }}
{{ with .Description }}{{ $desc := printf `content=%q` . | safeHTMLAttr }}
{{ else }}
	{{ if .IsPage }}{{ $desc := printf `content=%q` .Summary | safeHTMLAttr }}
	{{ else }}
		{{ with .Site.Params.description }}{{ $desc := printf `content=%q` . | safeHTMLAttr }}{{ end }}
	{{ end }}
{{ end }}
{{ return $desc }}

```

---

<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:** [August 27, 2020, 4:34pm UTC](https://discourse.gohugo.io/t/about-return/27864/2 "2020-08-27T16:34:47Z")

</div>

Yes, you can nest partial calls.

markdown

```auto
Answer: {{< foo 6 >}}

```

layouts/shortcodes/foo.html

```auto
{{ partial "mul-7.html" (.Get 0) }}

```

layouts/partials/mul-7.html

```auto
{{ return (partial "div-21.html" (mul 7 .)) }}

```

layouts/partials/div-21.html

```auto
{{ return (div . 21) }}

```

rendered html

```auto
<p>Answer: 2</p>

```

---

<div class="post-metadata">

**Author:** ![hucste](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/hucste/32/10014_2.png) [@hucste](https://discourse.gohugo.io/u/hucste)\
**Post date:** [August 27, 2020, 5:21pm UTC](https://discourse.gohugo.io/t/about-return/27864/3 "2020-08-27T17:21:54Z")

</div>

Ok, but into your example, you use shortcode.  
and about template?

If I include the code on partial (showed on my first port), name “return-decription.html”, on partial “meta.html”, as:  
`<meta name="description" {{ with partial "return-description.html" . }}{{ $desc }}{{ end }}>`

I’ve not any result. 🤔  
What’s wrong?!

---

<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:** [August 27, 2020, 5:31pm UTC](https://discourse.gohugo.io/t/about-return/27864/4 "2020-08-27T17:31:28Z")

</div>

Calling a partial from a template vs. calling a partial from a shortcode – no difference.

Partials return a _value_, not a variable. Additionally, [`with`](https://gohugo.io/functions/with) “rebinds the context ( `.` ) within its scope.”

So don’t do this:

```auto
{{ with partial "return-description.html" . }}{{ $desc }}{{ end }}

```

Do this:

```auto
{{ with partial "return-description.html" . }}{{ . }}{{ end }}

```

---

<div class="post-metadata">

**Author:** ![hucste](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/hucste/32/10014_2.png) [@hucste](https://discourse.gohugo.io/u/hucste)\
**Post date:** [August 27, 2020, 5:37pm UTC](https://discourse.gohugo.io/t/about-return/27864/5 "2020-08-27T17:37:47Z")

</div>

> [@jmooring](#):
>
> Calling a partial from a template vs. calling a partial from a shortcode – no difference

OK, you reassure me! 😛

* * *

> [@jmooring](#):
>
> `{{ with partial "return-description.html" . }}{{ . }}{{ end }}`

empty! ☹  
`<meta name="description" >`

* * *

If I write:  
`<meta name="description" {{ return ( partial "return-description.html" . ) }}>`

No code is displaying! ☹

---

<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:** [August 27, 2020, 5:43pm UTC](https://discourse.gohugo.io/t/about-return/27864/6 "2020-08-27T17:43:31Z")

</div>

I can help you if share your repository.

Please post a link to the public repository for your site. See:  
[https://discourse.gohugo.io/t/requesting-help/9132](https://discourse.gohugo.io/t/requesting-help/9132)

> Include a **link to the source code repository** of your project, because we really need the _context_ of seeing your templates and partials to be able to help you. It is trivial to do a quick `git clone` on your repo, then run `hugo server` in your project, to help you out. On the other hand, recreating your code from screenshots, or sort of guessing at it, is not.

> If you can’t share your repository for whatever reason, consider creating a dummy repo that you _can_ share, which reproduces the problem you’re experiencing.

---

<div class="post-metadata">

**Author:** ![hucste](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/hucste/32/10014_2.png) [@hucste](https://discourse.gohugo.io/u/hucste)\
**Post date:** [August 27, 2020, 5:48pm UTC](https://discourse.gohugo.io/t/about-return/27864/7 "2020-08-27T17:48:55Z")

</div>

> [@jmooring](#):
>
> Please post a link to the public repository for your site

I Known, but i’m on the local development.

> **[Sign in · GitLab](https://framagit.org/users/sign_in)**
>
> Framagit

I go to push this test code.

> **[Sign in · GitLab](https://framagit.org/users/sign_in)**
>
> Framagit

> **[Sign in · GitLab](https://framagit.org/users/sign_in)**
>
> Framagit

---

<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:** [August 27, 2020, 6:06pm UTC](https://discourse.gohugo.io/t/about-return/27864/8 "2020-08-27T18:06:54Z")

</div>

See [https://golang.org/pkg/text/template/#hdr-Variables](https://golang.org/pkg/text/template/#hdr-Variables). You are initializing variables instead of assigning value. Use `:=` to initialize, and `=` to assign value. Initialize once, assign value as needed.

---

<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:** [August 27, 2020, 6:09pm UTC](https://discourse.gohugo.io/t/about-return/27864/9 "2020-08-27T18:09:43Z")

</div>

I think a _careful_ read of these resources will be helpful:

- [https://golang.org/pkg/text/template](https://golang.org/pkg/text/template)
- [https://regisphilibert.com/blog/2018/02/hugo-the-scope-the-context-and-the-dot/](https://regisphilibert.com/blog/2018/02/hugo-the-scope-the-context-and-the-dot/)
- [https://gohugo.io/functions/with/](https://gohugo.io/functions/with/)

---

<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 29, 2020, 6:09pm UTC](https://discourse.gohugo.io/t/about-return/27864/10 "2020-08-29T18:09:45Z")

</div>

Closed on August 29, 2020, 6:09pm UTC

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