tyler-sommer / stick

A golang port of the Twig templating engine
MIT License
183 stars 36 forks source link

Filesystemloader seems unable to process if statement #25

Closed mingwho closed 4 years ago

mingwho commented 4 years ago

Say if we have a file test.twig like following

{% if 1 == 1 %}
1 equals 1
{% endif %}

Our script to render this template is as following

fsRoot, _ := os.Getwd()
env := stick.New(stick.NewFilesystemLoader(fsRoot))
p = map[string]stick.Value{"name": "World"}
env.Execute("test.twig", os.Stdout, p)

It should print "1 equals 1", but right now it is not printing anything. Did I miss something here or is this a bug we need to fix?

tyler-sommer commented 4 years ago

Hi @mingwho, thanks for opening this!

I've tried what you described, adding to test.twig:

{% if 1 == 1 %}
1 equals 1
{% endif %}

and to main.go:

package main

import (
        "os"

        "github.com/tyler-sommer/stick"
)

func main() {
        fsRoot, _ := os.Getwd()
        env := stick.New(stick.NewFilesystemLoader(fsRoot))
        p := map[string]stick.Value{"name": "World"}
        err := env.Execute("test.twig", os.Stdout, p)
        if err != nil {
                panic(err)
        }
}

When I run it, I get the expected output:

$ go run main.go

1 equals 1

In your example, it appears like you may not be handling the possible error returned by env.Execute. Can you confirm that the error is nil?

mingwho commented 4 years ago

Oh my! Thanks for pointing this out. I edited some code in the library on my local env and it was causing an error, but I didn't see it. THANK YOU! It's working proper