I have an app that uses a couple of shared templates to output HTML pages
using text/template. I'd like to be able to selectively include javascript
in the footer based on the page I'm currently on.
I know this isn't quite right, but here's what I'd like to do:
header.html: (not important for this example)
<html><head><title>{{ .pagetitle }}</title></head><body>
index.html:
{{ template "header.html" . }}
<h1>Home Page</h1>
{{ define "footer-extra" }}
<script src="/static/js/index-onload.js"></script>
{{ end }}
{{ template "footer.html" . }}
footer.html
<script src="/static/js/jquery-1.8.0.min.js"></script>
{{ template "footer-extra" }}
</body></html>
This sort of kind of works, actually, but it appears that defining a
template within a template makes it instantly global, and *all* the pages
include the same thing in the footer, no matter what the calling template
says.
What's the best way to do what I'm trying to do?
--