tyler-sommer / stick

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

Execute vs Render #14

Closed harikt closed 6 years ago

harikt commented 6 years ago

Hi @tyler-sommer ,

First I would like to thank you for your good work.

I have a question why have you opted for Execute rather than Render ?

Doesn't render makes api vice very close to Twig itself ?

tyler-sommer commented 6 years ago

There are many differences in the implementation details. In Twig, you either compile a template into PHP or use the template itself to render itself. This, IMO, is a poorly (tightly) coupled design, so I opted to draw very clear lines between the components in stick.

For that reason, I ended up with:

In this way, the Env is simply a registry for functions, filters, etc, and actually delegates to individual instances of state, which also means each template execution is thread-safe.

Additionally, since Go is not interpreted, "compiling" templates is more tricky. You can see a proof-of-concept I've started over in go-stickgen.

Long story short, the components and API at the core are actually quite different, but the end result is still compatible with Twig. Granted, there are still a TON of Twig Core functions, filters, tests, etc to implement before it is truly "Twig-compatible". But the Twig language itself is fully supported by stick.

Thanks for taking a look at stick! Let me know if you have any other questions. :)

harikt commented 6 years ago

Let me know if you have any other questions. :)

Not for now :) .

Thank you for your time to explain the details.