Pregunta

So I have the following equality test in a go template

{{if eq .user.Role "Manager" "Admin"}}

which should work according to the docs and the 1.2 release notes, but I'm not having any luck

To make it more clear .user.Role "Manager" would work, or any equality test that involves only one argument. So something like {{if eq 1 1}} evaluates correctly, but {{if eq 1 2 1}} does not.

Error I get is 3: executing ".../index.html" at : wrong number of args for eq: want 2 got 3

¿Fue útil?

Solución 2

I can think of two possibilities. Either you aren't on version 1.2 (what does go version give?) or somewhere in the pipeline the eq function was replaced in the template's FuncMap. Unfortunately, it's not exported, so I can't think of a good way to know if the latter is the case. If you haven't replaced it, are you using a package that modifies the pipeline? If so, try the rendering without any packages and see if it works.

Otros consejos

Ok so the final solution was to uncomment the eq implementation that revel has in template.go.

http://golang.org/src/pkg/text/template/exec_test.go#L71

You would need to export user (User) to make it accessible.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top