How to use the liquidjs.Context function in liquidjs

To help you get started, weโ€™ve selected a few liquidjs examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github BuilderIO / builder / packages / shopify / js / index.ts View on Github external
get(str: string, state = this.state) {
    // TODO: better solution e.g. with proxies
    let useStr = str.replace(/selected_or_first_available_variant/g, 'variants[0]');
    // TODO: warn for errors
    return liquid.evalValueSync(useStr, new Context(state, undefined, true)) || '';
  }
github BuilderIO / builder / packages / shopify / js / index.ts View on Github external
assign(str: string, state = this.state) {
    const re = /^\s*([^=\s]+)\s*=(.*)/;
    let useStr = str.replace(/selected_or_first_available_variant/g, 'variants[0]');
    const match = useStr.match(re)!;
    const key = match[1].trim();
    const value = match[2];
    const result = liquid.evalValueSync(value, new Context(state, undefined, true));
    console.debug('Liquid setting', key, 'to', result, 'via', str, state);
    state[key] = result;
  }
}

liquidjs

A simple, expressive and safe Shopify / Github Pages compatible template engine in pure JavaScript.

MIT
Latest version published 14 days ago

Package Health Score

86 / 100
Full package analysis

Popular liquidjs functions