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

dynamic partials cause (lookupProperty(...) || (depth0 && lookupProperty(...)) || alias3).call is not a function #1727

Closed
leonardlin opened this issue Dec 9, 2020 · 5 comments

Comments

@leonardlin
Copy link

Before filing issues, please check the following points first:

Used versions:
handlesbars: 4.7.6

partials is saved in:
/views/partials/filename.handlesbars
varPartial = 'filename';

main template uses
{{> (varPartial)}}

outcome:

TypeError: (lookupProperty(...) || (depth0 && lookupProperty(...)) || alias3).call is not a function
at Object.eval [as main] (eval at createFunctionContext (/usr/src/app/node_modules/handlebars/dist/cjs/handlebars/compiler/javascript-compiler.js:262:23), :11:148)
at main (/usr/src/app/node_modules/handlebars/dist/cjs/handlebars/runtime.js:208:32)
at ret (/usr/src/app/node_modules/handlebars/dist/cjs/handlebars/runtime.js:212:12)
at ret (/usr/src/app/node_modules/handlebars/dist/cjs/handlebars/compiler/compiler.js:519:21)
at ExpressHandlebars._renderTemplate (/usr/src/app/node_modules/express-handlebars/lib/express-handlebars.js:253:10)
at ExpressHandlebars.render (/usr/src/app/node_modules/express-handlebars/lib/express-handlebars.js:166:21)
at async ExpressHandlebars.renderView (/usr/src/app/node_modules/express-handlebars/lib/express-handlebars.js:224:15)

If I use
{{> 'filename'}}

It works

reproduced on fiddle:
Works with fix partial-name: https://jsfiddle.net/t9p508or/

Error with dynamic partial-name: https://jsfiddle.net/t9p508or/1/

@knownasilya
Copy link

knownasilya commented May 11, 2021

Getting this same error when express-handlebars passes a template to compile to hbs, although I'm not using any partials at all.

The code in the template looks like this:

(lookupProperty(helpers,"json")||(depth0 && lookupProperty(depth0,"json"))||alias3).call(alias2,(depth0 != null ? lookupProperty(depth0,"googleMaps") : depth0),{"name":"json","hash":{},"data":data,"loc":{"start":{"line":102,"column":32},"end":{"line":102,"column":53}}})

@knownasilya
Copy link

Ah looks like the helper was defined in a .ts file, but required so the .default wasn't used.

@beshur
Copy link

beshur commented Nov 12, 2021

So is there a resolution for this one?

@jaylinski
Copy link
Member

You can use the lookup-helper, as described in the docs:

var template = Handlebars.compile("{{name}} ({{age}} years old) {{> (lookup . 'partialName')}}");
var partial = Handlebars.compile('and has lastname {{lastname}}');

Handlebars.registerPartial('lastpartial', partial);

document.getElementById('output').innerHTML = template({name: 'Max', age: 38, partialName: 'lastpartial', lastname: 'Lee'});

@solo-exe
Copy link

solo-exe commented Sep 9, 2022

I had this persisting for a long time , I figured out it was occurring because I passed a boolean variable into the "if" helper enclosed in a bracket [ {{#if ()}} ], apparently it is not supposed to be passed in that manner. It is supposed to be passed like this [ {{#if }} ]

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

5 participants