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

No promise #468

Closed
Cirrusware opened this issue Dec 13, 2019 · 4 comments
Closed

No promise #468

Cirrusware opened this issue Dec 13, 2019 · 4 comments

Comments

@Cirrusware
Copy link

Hello,

I would like to use this render without promise. Is it possible ?
If I use an async/await on render function, I get a promise in return.

Thanks.

@ericmorand
Copy link
Member

ericmorand commented Dec 16, 2019

Hi,

This is strange because both TwingEnvironment::render and TwingTemplate::render return a Promise and should work flawlessly with async/await structure.

Can you share a code snippet that doesn't work as you expect?

@Cirrusware
Copy link
Author

export async function renderTwig(data, params) {

if (typeof params !== "object") {
    throw new Error("params must be of type object");
}

if (data) {

    let mdata = md5(data) + '.twig',
        templates = {}
    ;

    templates[mdata] = data;
    let loader = new TwingLoaderArray(templates),
        twig = new TwingEnvironment(loader, {'cache': false}),
        ret = await twig.render(mdata, params);
  
    return ret;
}

return "";

}

I must convert one URL like this
https://www.domain.org/?id={{user.id}}

and I get this in my src
[object Promise]

@ericmorand
Copy link
Member

How are you calling this renderTwig function?

If you don't call it with let output = await renderTwig(...) then it's normal that you get a Promise.

@Cirrusware
Copy link
Author

Exactly, But twig.render(mdata, params); return also a promise.

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

No branches or pull requests

2 participants