How to write multiline code to declare a complex dictionary?

I have a breadcumb partial template.
To use it I need to pass a dictionary of dictionaries, something like this:

{{ partial "breadcumb" ( dict "context" . "items" ( dict "1" ( dict "Url" "someUrl" "Name" "SomeName" ) "2" ( dict "Url" "someUrl" "Name" "SomeName" ) "3" ( dict "Url" "someUrl" "Name" "SomeName" ) ) ) }}

There is a better way to write this piece of code?
I tried something like this:

{{ partial "breadcumb" ( dict "context" . "items" ( dict "1" ( dict "Url" "someUrl" "Name" "SomeName" ) "2" ( dict "Url" "someUrl" "Name" "SomeName" ) "3" ( dict "Url" "someUrl" "Name" "SomeName" ) ) ) }}

But it show the “unclosed action” error.

Thanks.

2 Likes

Unfortunately, the lack of newline support in actions appears to be a Go template package limitation:

Except for raw strings, actions may not span newlines, although comments can.

Yeah, you are right.
As a workaround I did this:

{{ $bLink1 := ( dict “Url” “someUrl” “Name” “SomeName” ) }}
{{ $bLink2 := ( dict “Url” “someUrl” “Name” “SomeName” ) }}
{{ $bLink3 := ( dict “Url” “someUrl” “Name” “SomeName” ) }}
{{ partial “breadcumb” ( dict “context” . “items” ( dict “1” $bLink1 “2” $bLink2 “3” $bLink3 ) ) }}

1 Like

Hi there,
Still no newline support right?

This feature is related to this GitHub issue, which was closed in the late of 2020. Yet, this does not work as expected.

Note that this will be fixed in the next Hugo version.

4 Likes

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