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

Update jsonParseSafe.js - Inline use patch #341

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

34638a
Copy link

@34638a 34638a commented Feb 7, 2025

Add patch to allow for #JSONparseSafe to be used as a inline helper.

Examples:
{{log (JSONparseSafe '{"test":"variable"}')}}
{{log (lookup (JSONparseSafe '{"test":{"validate":"variable"}}') "test")}}

What? Why?

To prevent this situation which makes code so much harder to maintain and reason with:

{{! Pretend at this layer there is a pagination object here }}

{{! Before}}
{{#JSONparseSafe '{"test": "hello world!"}'}}
    {{#with this}}
        {{log test}}
        {{log ../../pagination}}
    {{/with}}
{{/JSONparseSafe}}


{{! After}}
{{#with (JSONparseSafe '{"test": "hello world!"}')}}
    {{log test}}
    {{log ../pagination}}
{{/with}}

This change removes a extra layer of context shifting ( ../ ) to access information about the context window.

How was it tested?

Local tests, modified local theme testing file.

cc @bigcommerce/storefront-team

Add patch to allow for #JSONparseSafe to be used as a inline helper.

Examples:
`{{log (JSONparseSafe '{"test":"variable"}')}}`
`{{log (lookup (JSONparseSafe '{"test":{"validate":"variable"}}') "test")}}`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

1 participant