Passing multiple parameters from template to template

I have several pages with Go html templates (without any parameters sent from Go).

The main template should send 2 string parameters to next template.

{{template "httpend" "main" "sub"}}

The other template with a script should be able to receive these parameter and fire a Javascript function.

{{define "httpend"}}

<script src="/js/menu.js" defer></script>
<script src="/js/nav.js" defer></script>
    window.onload = function() {


The purpose of this is to make it more DRY. Repeating the script on every page is harder to maintain.

There are NO dots parameters sent from Go. (.main .sub). Just plain strings…

No errors reported, but the httpend template will not show up for some reason. And hence not fired.

How can I send multiple strings as parameters to another Go html template?

Use a struct or map context and use appropriate names to create and access.

You can not have more than one context, or “arguments” into as single template.

Using HTML?

No, the template syntax and system.

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