Shortcode and partial arguments: how to do this?

Hugo is making me despair. Let’s start with a .md page

{{<myshortcode title="title">}}

then in myshortcode.html:

{{- $var1 := $.Get "title" }}
{{ $var2 := partial "func/FunctionPartial.html" (dict "param" $var1) }}

in func/FunctionPartial.html how can I read and manipulate the input parameter? They all give errors!

{{- $myvar := .Get "param) }} <-- execute of template failed at <.Get>: Get is not a method but has arguments
{{- $myvar := (.Get "param") }} <-- error
{{- $myvar := .param }} <-- error
{{- $myvar := .Param }} <-- error

I don’t need page context, just to read that parameter and return it decorated, I don’t think I need dot context for that:

{{ $ret := printf "<p class=\"mt0 white\">%s</p>" $ret }}
{{ return $ret }}

More than anything, I would like to understand how to pass parameters from page > shortcode > partial.

Using $.Scratch I can obtain the result, but I don’t like this way.

Thank you

That’s correct, unless the dot isn’t what you think it is, in which case you need to get to the top-level context:

{{ $myvar := $.param }}


So what am I doing wrong? Or what am I not knowing?

in my shortcode:

{{ $tit2 := partial "func/GetCappelloOrari.html" (dict "titolo" $titolo) }}

this is func/GetCappelloOrari.html (all code is here)

{{- $ret := $.titolo }}
{{- return $ret }}

Hugo says:
execute of template failed at <$.titolo>: can’t evaluate field titolo in type *hugolib.ShortcodeWithPage

and highlight this:
{{- $ret := $.titolo }}

I don’t have enough information. Please post a link to the public repository for your project.

See Requesting Help.

Let us see your code

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.


Thanks, I understand that you need me to create a dummy repo, but you create two files first before I create a dummy repo.

make a shortcode with just this line:

{{ $tit2:= partial "func/GetCappelloOrari.html" (dict "title" "ciaone") }}

make a partial with just these 2 lines:

{{- $ret := $.title }}
{{- return $ret }}

If you don’t get any errors, it means I’ll have to wait for a next version of Hugo, maybe.

Even closing and reopening Hugo seems to have no effect.

I’ve already done that, and cannot reproduce the error.


This is a “you” problem not a Hugo problem.

1 Like