You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is a documentaion bug! When using a programatically defined template the docs state: "The third argument to loadTemplate is a boolean describing whether the template is async or not. By default, Eta will assume that the template is synchronous."
Using this advice, calling a programatically defined template using renderAsync will result in an EtaNameResolution error. (includeAsync has the same issue)
To Reproduce:
consteta=newEta();consttest=`test`;eta.loadTemplate('@test',test,true);// As advisedconstres=awaiteta.renderAsync('@test');
EtaNameResolutionError [EtaNameResolution Error]: Failed to get template '@test'
Expected Behaviour:
The template should be found and rendered.
Package & Environment Details
Environment: Node: 21.5.0
Version: 3.4.0
Additional Context:
Removal of the Async call will succeed:
consteta=newEta();consttest=`test`;eta.loadTemplate('@test',test,true);// Boolean variable is doing nothingconstres=eta.render('@test');console.log(res);
As will passing the object that the code actually expects:
Just a slighly more complete example to assist future travellers who are loading their templates from a database (or wherever!) while the documentation / examples for Eta are still rather sparse:
consteta=newEta({tags: ['<?','?>'],// I find <% awkward to type (long live PHP!)varName: 'data',// Not a fan of `it` eitherdebug: true,cache: true,});constlayoutTest=` <!DOCTYPE html> <html> <head> <title><?= data.title ?></title> </head> <body> <?~ await includeAsync('@headerTest', data) ?> <?~ data.body ?> <?~ await includeAsync('@footerTest', data) ?> </body> </html>`;constheaderTest=` <header> Header: <?= data.title ?> </header>`;constfooterTest=` <footer> Footer: <?= data.title ?> </footer>`;constmainTest=` <? layout('@layoutTest', data) ?> <main> <h1>Main: <?= data.title ?></h1> </main>`;eta.loadTemplate('@layoutTest',layoutTest,{async: true});eta.loadTemplate('@headerTest',headerTest,{async: true});eta.loadTemplate('@footerTest',footerTest,{async: true});eta.loadTemplate('@mainTest',mainTest,{async: true});constres=awaiteta.renderAsync('@mainTest',{title: 'Test title'});
The text was updated successfully, but these errors were encountered:
@paul-norman thanks for catching that! I just pushed a quick clarification to the docs, but I'd be open to a PR with more details / a better explanation!
I've just started actually porting some EJS code to ETA today, so I'm a total beginner with the system. However, after I've used it for a little while I will take another look at the docs and see what doesn't make sense to me then...
Describe the Bug:
This is a documentaion bug! When using a programatically defined template the docs state: "The third argument to loadTemplate is a boolean describing whether the template is async or not. By default, Eta will assume that the template is synchronous."
Using this advice, calling a programatically defined template using
renderAsync
will result in anEtaNameResolution
error. (includeAsync
has the same issue)To Reproduce:
Expected Behaviour:
The template should be found and rendered.
Package & Environment Details
Additional Context:
Removal of the Async call will succeed:
As will passing the object that the code actually expects:
Just a slighly more complete example to assist future travellers who are loading their templates from a database (or wherever!) while the documentation / examples for Eta are still rather sparse:
The text was updated successfully, but these errors were encountered: