Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add parameter to not throw error when can't parse string #751

Open
RomanKuzo opened this issue Sep 16, 2024 · 2 comments
Open

Add parameter to not throw error when can't parse string #751

RomanKuzo opened this issue Sep 16, 2024 · 2 comments

Comments

@RomanKuzo
Copy link

Hey

I'm using this package to interpolate string and insert some data into it.

Example:

I have a string like this: "Hi, this is {{user.first_name}} {{user.last_name}}". And the object of values:

const defaultValues = {
  user: {
    email: '{{user.email}}',
    first_name: '{{user.first_name}}',
    fullname: '{{user.fullname}}',
    last_name: '{{user.last_name}}',
    phone: '{{user.phone}}',
};

It works as expected when everything is okay. But when there is a mistake in a variable it throws me an error (it's also good).
My request is to add an option to skip variables in case of a parsing error and just return this string.

Example:

If I have a string like this: "Hi, this is {{user.first_name} {{user.last_name}}" it should return me a string like this: "Hi, this is {{user.first_name} Kuzo".

Please, let me know if it's possible.

Thanks

Roman Kuzo

@harttle
Copy link
Owner

harttle commented Sep 22, 2024

Hi @RomanKuzo ,

There's multiple errors LiquidJS can throw, apart from unmatched {{. Like unmatched {%, invalid filter syntax, etc. Not sure if skipping this one error works for you.

A general advice would be try parse and render, then fallback to a default string, in case of template not trusted.

@mohas
Copy link

mohas commented Sep 23, 2024

I generally advice against this as it will introduce unnoticed mistakes and headaches. if you have data entry process and fear that users might not be advanced enough to enter correct format you can run the template through a sample data and show the result and also prevent user from saving until successful compilation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants