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

Setting globals dynamically after opts argument removed from renderFile() #432

Closed
PlanetIrata opened this issue Dec 9, 2021 · 5 comments

Comments

@PlanetIrata
Copy link

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

@PlanetIrata
Copy link
Author

My problem is to find a way to modify globals dynamically after the creation of the engine (without recreating it).

The renderFile function allowed this prior to version 9.26.0

Thanks for your help!

@harttle harttle changed the title renderFile "opts" parameter removed from 9.26.0 brokes my app Setting globals dynamically after opts argument removed from renderFile() Dec 10, 2021
github-actions bot pushed a commit that referenced this issue Dec 11, 2021
# [9.29.0](v9.28.6...v9.29.0) (2021-12-11)

### Features

* customize globals & strictVariables when calling render, see [#432](#432) ([6801552](6801552))
@harttle
Copy link
Owner

harttle commented 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

@amit777
Copy link
Contributor

amit777 commented Dec 11, 2021

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

@amit777
Copy link
Contributor

amit777 commented Dec 11, 2021

just an FYI. The reason we need this is each customer has different global settings. Currently, we create one engine object per customer which seems wasteful. Being able to pass in customer-specific globals into the render function will allow us to not have to create a liquid engine for each customer!

@PlanetIrata
Copy link
Author

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!

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

No branches or pull requests

3 participants