question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Custom tag registration doesn't work in Liquid v10

See original GitHub issue

Hi. In Liquidjs v9 I have the following code to create custom tags:

engine.registerTag('upper', {
  parse: function(tagToken, remainTokens) {
      this.str = tagToken.args;
  },
  render: async function(ctx) {
      const str = await this.liquid.evalValue(this.str, ctx);
      return str.toUpperCase();
  }
});

This code fails in Liquid 10: Uncaught RenderError: Cannot read properties of undefined (reading 'toUpperCase').

I found this example in the documentation but it doesn’t work either:

engine.registerTag('upper', {
    parse: function(tagToken) {
        this.str = tagToken.args; // name
    },
    render: function*(ctx) {
        const str = yield this.liquid.evalValue(this.str, ctx);
        return str.toUpperCase()
    }
});

Issue Analytics

  • State:closed
  • Created 9 months ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
oscaroterocommented, Dec 12, 2022

Thanks for the fast response.

Performance-wise, it’s better to create new Value() during parse, and call value.value() in render(). As in the implementation of builtin tags.

I don’t have any preference, so if it’s more perfomant this suggestion, I’ll change it. Can you provide an example for that (or update the example in the documentation)? Somethig like this:

engine.registerTag('upper', {
  parse: function(tagToken, remainTokens) {
      this.val = new Value(tagToken.args);
  },
  render: async function(ctx) {
      const str = this.val.value();
      return str.toUpperCase();
  }
});
0reactions
oscaroterocommented, Dec 13, 2022

Perfect. Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to rewrite a registerTag from v9 to be v10 compatible?
However it complains that value does not exist on Tag , that token cannot be found as well as that liquid cannot be...
Read more >
Rails 3 with Liquid Custom Tags not found
Then created an initializer (in config/initializers) responsible for registering the custom tags with Liquid. i.e.. Liquid::Template.register_tag('custom_tag', ...
Read more >
How to check the mailing status of my online custom or ...
Allow at least six weeks for the custom plates to arrive. Your new registration documents will be mailed separately from your new custom...
Read more >
Welcome to the Vanity Plate Search & Order Online Service
Maine registrants with a current vehicle registration who wish to display a personalized license plate on their vehicle. Who CANNOT use this service?...
Read more >
The7 — Website and eCommerce Builder for WordPress
The7 is designed to work in synergy with Elementor and WooCommerce. ... Pre-made Websites (or Demo Sites) not only showcase the theme ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found