liquid-rust icon indicating copy to clipboard operation
liquid-rust copied to clipboard

Open to the idea of supporting less strict parsing/rendering as an option?

Open RyanAmos opened this issue 2 years ago • 3 comments

Following up from my comment left on this issue.

I have a use-case where it's necessary for us to reduce the rendering strictness, specifically for variables. We allow users to define their own templates and store them. Those templates are then used later to render values with global variables provided by the customers' data which may or may not have all of the variables present. Our current implementation just renders those missing variables as an empty string.

I've tried multiple work arounds to get around this, some of which were fairly hacked together, but they all had edge cases that weren't handled properly.

I'm curious if you're open to the idea of adding a "lax" rendering mode?

RyanAmos avatar Jan 09 '23 16:01 RyanAmos

I'd be open to an outside contributor adding this if

  • It isn't too invasive
  • It doesn't dramatically affect performance
  • It is off by default

The first issue I see with implementing this is "where". The Runtime trait is a natural place but we build up runtimes throughout the execution of the template, stacking them on top of each other, so there is no top-level runtime to provide this behavior.

We might be able to handle a templated type that wraps the Runtime and all calls actually take this, rather than a runtime directly to ensure it gets used. It'll get a bit messy but likely would work.

epage avatar Jan 10 '23 15:01 epage

I have a local branch that I believe follows all of your requirements. I could be missing something within the implementation, but I'll push up a PR to start getting feedback today.

RyanAmos avatar Jan 10 '23 15:01 RyanAmos

PR opened, open to any and all suggestions: https://github.com/cobalt-org/liquid-rust/pull/492

RyanAmos avatar Jan 10 '23 17:01 RyanAmos