About return…

First, very good idea! :smiley:

I read this topic:

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

By instance, with this code:

{{* 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 }}

Yes, you can nest partial calls.


Answer: {{< foo 6 >}}


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


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


{{ return (div . 21) }}

rendered html

<p>Answer: 2</p>

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. :thinking:
What’s wrong?!

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

Partials return a value, not a variable. Additionally, with “rebinds the context ( . ) within its scope.”

So don’t do this:

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

Do this:

{{ with partial "return-description.html" . }}{{ . }}{{ end }}
1 Like

OK, you reassure me! :stuck_out_tongue:

empty! :frowning:
<meta name="description" >

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

No code is displaying! :frowning:

I can help you if share your repository.

Please post a link to the public repository for your site. See:

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.

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

I go to push this test code.

See 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.


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

1 Like

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