Setting `.Get 0` in layout file to access a shortcode from a partial

Feeling a bit stupid because I remember to have used something similar:

I want to use the cloakemail shortcode as a partial.

So I put this code into layouts/partial/cloakemail.html and this into layouts/shortcodes/cloakemail.html:

{{ partial "cloakemail.html" . }}

This is working fine when calling the shortcode from within a content file.

How can I use this partial from a template? Passing something like dict "test" "my test" is no problem, but how can a simulate .Get "address" or .Get 0?

This is what I tried in baseof.html:

{{ partial "cloakemail" (dict (.Get "address") "me@mail.com") }}

Thank you!

The way to go would be to use Inline Shortcodes

This is how I pass values from a content file to a partial.

Thanks a lot!

Yes, I have worked with Inline Shortcodes. What I need is the possibility to pass a value from a template/layout file:

layout file --> partial --> shortcode.

The shortcode requires e.g. .Get 0; but I cannot pass such a variable from the layout file, can I?

No you cannot render a layout value with .Get 0 in a shortcode. This is meant for direct input in the shortcode from a content file.

But there may be another way to achieve what you want. If you could share a sample minimal repo with your setup I’ll have a look.

Hi @alexandros!

Thanks again! Appreciate it.

I wanted to use this shortcode as a partial to follow a DRY method.

But as this is not (easily) possible I just just copied the shortcode to layouts/partials and modified it a bit:

{{- $address := .address -}}
{{- $protocol := "mailto" -}}
{{- $class := .class -}}
{{- $displaytext := .display -}}
…

Now I can use this partial in the layout using

{{ partial "cloakemail" (dict "address" "me@email.com" "display" "My text" "class" "my-class") }}