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

tmpl.render is not a function #21

Open
bjunc opened this issue Nov 29, 2016 · 3 comments
Open

tmpl.render is not a function #21

bjunc opened this issue Nov 29, 2016 · 3 comments

Comments

@bjunc
Copy link

bjunc commented Nov 29, 2016

The code below throws the error: tmpl.render is not a function(…)

helloworld.nunj

Hello {{ person }}

app.js

var tmpl = require("./helloworld.nunj");

console.log("HelloWorld tmpl:", tmpl);
tmpl.render({person:"World"});

The output of tmpl is a function that looks like this:

function (ctx, cb) { return nunjucks.render("PATH_TO_NUNJ_FILE", ctx, cb); }

I can actually get the template to render, by treating it as a function:

var tmpl = require("./helloworld.nunj");
tmpl({person:"World"});

However, if I don't use nunjucksify, I can get the expected result:

var nunjucks = require('nunjucks');

var tmpl2 = new nunjucks.Template('Hello {{ person }}');
tmpl2.render({person:"World"});

Any thoughts?

@bjunc bjunc changed the title Trouble behaving as expected tmpl.render() is not a function Nov 30, 2016
@bjunc bjunc changed the title tmpl.render() is not a function tmpl.render is not a function Nov 30, 2016
@kevinboudot
Copy link

Same issue.

@bjunc
Copy link
Author

bjunc commented Dec 2, 2016

@kevinboudot, I came across this error while evaluating Webpack vs Browserify. I ended up settling with Webpack (for lots of reasons), and the nunjucks-loader works great.

Not sure if that's an option for you, but I thought I'd share.

@sunrize531
Copy link

sunrize531 commented Jan 4, 2017

Well, it's clearly deliberate, just it breaks my code, and I'm not sure whether should I fix it, as it might be eventually considered as a bug, cause according to (massively outdated) documentation require should return Template object. I'd suggest taking asFunction parameter from transform options instead, and maybe set it to true by default, cause in most cases you need just that.

https://github.com/rotundasoftware/nunjucksify/blob/master/index.js#L41

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

3 participants