I would like to write such a conditional fragment in a Go HTML template :
{{if isUserAdmin}}
<a href"/admin/nuke">Go to the big red nuclear button</a>
{{end}}
However, this is not directly possible because the template is not aware of the request that triggered its execution, so it cannot determine if the user is admin or not.
Is there some normal way to achieve this ?
In advance I point out that :
- I do not want to use Pipelines for this specific data (see other question about this)
- I acknowledge that only the handlers/controllers should deal with logic, and views should only do the rendering. But the condition
{{if isUserAdmin}}
is not logic itself, it's a necessary construct to leverage a boolean value already calculated by the controller. - The Funcs method can help, but is currently not lean enough for easily defining specific method
isUserAdmin()