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

docs/api/rendering/ #67

Open
utterances-bot opened this issue Sep 12, 2023 · 4 comments
Open

docs/api/rendering/ #67

utterances-bot opened this issue Sep 12, 2023 · 4 comments

Comments

@utterances-bot
Copy link

Rendering | SquirrellyJS

Rendering a template compiles a template and then calls it with the data you pass to it.

https://squirrelly.js.org/docs/api/rendering

Copy link

Hi Squirrelly team,

Is there any setting or other API which can allow to ignore undefined properties in model?
For example callback to which undefined property name will be passed and replacement value will be returned.
I need to continue rendering template even when some properties in model are not found, better replacing with some defaults.

@nebrelbug
Copy link
Collaborator

@ValentinKostiuk you should be able to define a default filter.

@ValentinKostiuk
Copy link

@nebrelbug, Thank you for your response! Appreciate your time.
yep I did. Issue here is that:
Filter does not receive name of field as an argument (which could be useful)
Even if filter defined this approach works only for one level of "undefinedness" for example works for {{it.a}} but not for {{it.a.b}}. In the latest example it will fail with error "Cannot read properties of undefined (reading 'b')".

For now I've figured out tactics to parse template to AST (very useful API) find out which fields are absent in model and replace them with required defaults in model. Hope it'll work.

@nebrelbug
Copy link
Collaborator

@ValentinKostiuk sounds like it could be a cool plugin!

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

No branches or pull requests

3 participants