pongo2 icon indicating copy to clipboard operation
pongo2 copied to clipboard

Unable to subtract

Open daemocles opened this issue 2 years ago • 0 comments

I am trying to subtract an integer by 1 with the add filter, however there seems to be an issue with parsing negative integers

package main
import (
        "fmt"
        "github.com/flosch/pongo2/v5"
)
func main() {
        template, err := pongo2.FromString("{{ variable|add:-1 }}")
        if err != nil {
                panic(err)
        }
        context := pongo2.Context{"variable": 5}
        out, err := template.Execute(context)
        if err != nil {
                panic(err)
        }
        fmt.Println(out)
}

However, I get the following error: panic: [Error (where: parser) in <string> | Line 1 Col 17 near '-'] Expected either a number, string, keyword or identifier.

Also, adding quotes around the -1 ends up appending a -1 string at the end of my variable instead of actually subtracting.

daemocles avatar Feb 12 '22 22:02 daemocles