Simplify template reuse

I hope in the layout:

  1. Custom functions.
  2. Call the short code.
  3. partial uses ‘$’ to access the global context.
{{with index $.Site.Data.img .name}}

And then use it like this

{{partial "img" (dict "name" "image_name" "Site" $ .Site)}}

Why should things be so tedious if they could be reused?

I hope it can be used like this:

  1. Custom function: img name = image_name
  2. Call short code: call img name = image_name
  3. Partial access to the global context: partial" img "dict (" name "" image_name ")

Is this difficult?

I don’t understand what you are asking.

It is a template that is used repeatedly. At present, such a syntax is cumbersome. Each call uses a dictionary to store parameters and also pass a Site variable. I hope to simplify this syntax and propose 3 solutions.

To replace it:

{{partial "img" (dict "name" "image_name" "Site" $ .Site)}}

Please follow the advice at Requesting Help and share a repo. Otherwise folks are gonna have a difficult time testing out possible solutions.

Well you can use the global function site instead of .Site so your partial can now take a string for context:

{{ partial "img" "image-3.png" }}

The site function instead of .Site is great, so you don’t need to do extra passes.

Hasn’t it been added to the document yet?