tailscale / golink

A private shortlink service for tailnets
BSD 3-Clause "New" or "Revised" License
1.23k stars 79 forks source link

Pass hostname to all html templates #133

Closed armandocerna closed 3 months ago

armandocerna commented 3 months ago

We would like our html templates to reflect the hostname override we are passing to golink, these changes pass the hostname to all HTML templates

willnorris commented 3 months ago

rather than passing the hostname in as a variable, how about registering a function that can be used in all of the templates? It feels a tiny bit wrong to use "go" as the func name, since it's already a keyword, but it works pretty well since it's not actually a registered template func. So something like:

    tmplFuncs := template.FuncMap{
        "go": func() string {
            return *hostname
        },
    }

which is registered on all of the templates, and then inside the template files themselves, we can use {{go}}, which is still quite readable. I've got the start of this working if you're okay with me pushing it to your branch?

armandocerna commented 3 months ago

Much cleaner, I like it! Totally ok with you pushing to my branch.

armandocerna commented 3 months ago

I saw you were curious, very simple change we use so for the hostname we have an internal cli utility named the same