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.

Setting globals dynamically after opts argument removed from renderFile()

See original GitHub issue

Hi

I juste upgraded my app from LiquidJS 9.25.1 to the latest 9.28.6

I am facing bugs and just find that the optsparameter of renderFile has been removed in version 9.26.0 :

public async renderFile (file: string, ctx?: object, opts?: LiquidOptions) {
     const templates = await this.parseFile(file, opts)
     return this.render(templates, ctx, opts)
}

My app was using this parameter to pass a customized globals setting to the rendered file (depending on the file, this is why I don’t set the globals setting while creating the engine).

Is there another way to do this without re-creating an engine before each call to renderFile ?

P.S. as stated in #395 this should have been flagged as a breaking change in 9.26.0

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
amit777commented, Dec 11, 2021

This is fortuitous because I was looking to do something like this as well. It seems to work for me. Thanks!

0reactions
PlanetIratacommented, Dec 11, 2021

Hey @PlanetIrata, I think it makes sense to provide render specific options when calling .render(), try v9.29.0 with following:

const globals = {}  // the globals you need to set for this render call
engine.render(<file>, {}, {globals})

Feel free to post back if there’s more problems on this, or that doesn’t work for you. Please see this doc for details: https://liquidjs.com/api/classes/liquid_.liquid.html#renderFile

Hi @harttle

Seems to work perfectly with 9.29.0

Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Dynamically set R markdown title, output filename, and global ...
I know the title can be made dynamic through the params YAML header but that doesn't help with the output filename or within...
Read more >
You Can Definitely Use Global Variables To Manage Global ...
In both concepts the purpose of global(state & variable) is to allow sharing of a value among entities which might be functions, classes, ......
Read more >
4.2 Set the document title dynamically | R Markdown Cookbook
With the title being a dynamic parameter, you can easily generate a batch of reports with different titles. We used the title as...
Read more >
Handling dynamically created HTML in JavaScript - Medium
This is possible as the JavaScript is executed immediately after the elements are declared in the DOM — the elements are guaranteed to...
Read more >
API — Jinja Documentation (3.0.x)
To render it with some variables, call the render() method. ... If this is set to True the first newline after a block...
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