Hugo

[SOLVED] How to pass value to partial template?

Hello. My example.

{{ partial "contact_form" (dict "context" . "myVar" "val") }}

In contact_form.html I have {{ .myVar }} and I see a problem

Building sites … ERROR 2019/12/02 12:38:07 render of "section" failed: "d:\servers\gcorelu\src\themes\gcore\layouts\section\blog.html:1:3": execute of template failed: template: section/blog.html:163:3: executing "section/blog.html" at <partial "contact_form" .>: error calling partial: "d:\servers\gcorelu\src\themes\gcore\layouts\partials\contact_form.html:1:3": execute of template failed: template: partials/contact_form.html:1:3: executing "partials/contact_form.html" at <.myVar>: can't evaluate field myVar in type *hugolib.pageState
ERROR 2019/12/02 12:38:07 render of "taxonomy" failed: "d:\servers\gcorelu\src\themes\gcore\layouts\_default\taxonomy.html:1:3": execute of template failed: template: _default/taxonomy.html:250:3: executing "_default/taxonomy.html" at <partial "contact_form" .>: error calling partial: "d:\servers\gcorelu\src\themes\gcore\layouts\partials\contact_form.html:1:3": execute of template failed: template: partials/contact_form.html:1:3: executing "partials/contact_form.html" at <.myVar>: can't evaluate field myVar in type *hugolib.pageState
ERROR 2019/12/02 12:38:07 render of "section" failed: "d:\servers\gcorelu\src\themes\gcore\layouts\section\blog.html:1:3": execute of template failed: template: section/blog.html:163:3: executing "section/blog.html" at <partial "contact_form" .>: error calling partial: "d:\servers\gcorelu\src\themes\gcore\layouts\partials\contact_form.html:1:3": execute of template failed: template: partials/contact_form.html:1:3: executing "partials/contact_form.html" at <.myVar>: can't evaluate field myVar in type *hugolib.pageState

Why do I have the problem?

my template contact_form.html
{{ .myVar }}

The second parameter must be the context

{{ partial “contact_form” . }}

the partial has access to page etc…

I saw that


and that is now working

Thanks for solution!