Hello. I use a partial template in a partial. This is my structure.
For example:
index.tpl code:
{{ .Scratch.Set "Fields" "Name#1|Phone#1|Email%%File%%Message" }}
{{ partial "modules/Main" . }}
modules/Main.tpl code
{{ $FieldsRow := split ($.Scratch.Get "Fields") "%%" }}
{{ range $key, $Fields := $FieldsRow }}
<div class="field_form_f">
{{ $.Scratch.Set "FieldData" $Fields }}
{{ partial "modules/SwitchInput" . }}
{{ $.Scratch.Delete "FieldData" }}
</div>
{{ end }}
modules/SwitchInput.tpl code is:
{{ $FieldData := .Scratch.Get (string "FieldData") }}
{{ $Field := split ($FieldData) "|" }}
{{ range $key, $FieldValue := $Field }}
{{ $FieldTemp := split ($FieldValue) "#" }}
{{ index $FieldTemp 0 }}
{{ if eq (index $FieldTemp 0) "Name" }}
{{ if (index $FieldTemp 1) }}
{{ $.Scratch.Set "Filed_50" 1 }}
{{ end }}
{{ $.Scratch.Set "TextName" (T "NAME_text") }}
{{ $.Scratch.Set "Name" "contact_name" }}
{{ $.Scratch.Set "Type" "text" }}
{{ $.Scratch.Set "maxLength" 50 }}
{{ $.Scratch.Set "Require" 1 }}
{{ partial "modules/InputField" . }}
{{ end }}
{{ end }}
modules/InputField.tpl code is:
{{ $name := $.Scratch.Get "Name" }}
<div class="{{ if ($.Scratch.Get "Filed_50") }} class50{{ end }}">
<input id="{{ $name }}" type="{{ $.Scratch.Get "Type" }}" maxlength="{{ $.Scratch.Get "maxLength" }}" />
<label for="{{ $name }}">{{ $.Scratch.Get "TextName" }}{{ if ($.Scratch.Get "Require") }} *{{ end }}</label>
</div>
And My errors are
Rebuild failed:
Failed to render pages: render of “home” failed: execute of template failed: template: index.html:486:3: executing “index.html” at <partial “modules/Main” .>: error calling partial: “…\layouts\partials\modules\Main.html:1:25”: execute of template failed: template: partials/modules/Main.html:27:8: executing “partials/modules/Main.html” at <partial “modules/SwitchInput” .>: error calling partial: “…\layouts\partials\modules\ContactForm\SwitchInput.html:1:25”: execute of template failed: template: partials/modules/SwitchInput.html:1:25: executing “partials/modules/SwitchInput.html” at <.Scratch.Get>: can’t evaluate field Scratch in type string
hugo v0.81.0-59D15C97 windows/amd64 BuildDate=2021-02-19T17:07:12Z VendorInfo=gohugoio
Why .Scratch.Get param is not string?