jet icon indicating copy to clipboard operation
jet copied to clipboard

Added function to disable template rendering abort on error

Open kabukky opened this issue 5 years ago • 4 comments

We are currently evaluating Jet for our projects.

One thing that is different from a lot of other template languages (e. g. Handlebars) is how Jet handles expressions that cannot be evaluated.

E. g. accessing a non-valid field value will lead to the whole template rendering process being aborted and the error being returned. Handlebars would just insert an empty string into the place of the expression.

To enable this "Handlebars"-like behavior with Jet, I've added the abortTemplateOnError global variable that can be set from the outside via SetAbortTemplateOnError.

It works well with this template (document.yada is not set in this case, the if comparison is also not valid):

{{ document.title }}
{{ document.yada }}
{{ if "2006" < 2018 }}foooooooo{{end}}
{{ document.title }}

Do you see any problems with this? Node.errorf is used in a lot of other situations that I haven't checked yet

kabukky avatar Mar 04 '19 15:03 kabukky

Hi, @kabukky thanks for the contribution, can you send multiple pull requests ? Walking through the pull request i see many modifications unrelated with the meaning of the title of this pull request, this makes hard to evaluate and accept your pull request.

jhsx avatar Jul 28 '19 21:07 jhsx

Hi @jhsx Sorry, my master has diverged quite a bit by now.

The relevant changes are all in this commit: https://github.com/kabukky/jet/commit/b2a337d4bf9ced3209dc956d6a6b0fd2186f4c19

I'm still not sure if this is feasible, since it might have side effects. What is your take on it?

kabukky avatar Jul 29 '19 12:07 kabukky

Can you pull out https://github.com/kabukky/jet/commit/b2a337d4bf9ced3209dc956d6a6b0fd2186f4c19 into a new PR?

annismckenzie avatar Jan 03 '20 14:01 annismckenzie

@kabukky I believe this was handled with https://github.com/CloudyKit/jet/pull/152 but please chime in if it doesn't fit the use case somehow.

tooolbox avatar Jul 01 '20 17:07 tooolbox