Search code examples
gogo-html-template

Or statement in golang templates in combination with gt/lt (greaterThan, lowerThan)


I'm trying out the golang templates but I have one problem which don't know how to fix.

Single statements like below work good.

  {{ if gt .TotalPrice 0.0 }}

But a statement like the one below

  {{ if or gt .TotalPrice 0.0 gt .TotalMinutes 0.0 }}

Results in the following error.

 executing \"confirmEmail\" at <gt>: wrong number of args for gt: want 2 got 0

How does one fix this?


Solution

  • Ok, found a solution

    Based on: https://www.calhoun.io/intro-to-templates-p3-functions/

    You can add ( and )

    {{if (ge .Usage .Limit)}}
    

    So

    {{ if or (gt .TotalPrice 0.0) (gt .TotalMinutes 0.0) }}
    

    Fixed it :)