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 output... #7

Closed
svdoever opened this issue Jun 11, 2014 · 4 comments
Closed

No output... #7

svdoever opened this issue Jun 11, 2014 · 4 comments

Comments

@svdoever
Copy link

I posted this already on stackoverflow (http://stackoverflow.com/questions/24152877/handlebars-handlebars-helper-prettify-in-node-js-empty-result), but this seems a better place:

I try to use Handlebars with the prettify helper using the following code:

var handlebars = require("handlebars");
var helpers = require('prettify');

var templateHtml = "{{#prettify}}<div class='entry'><h1>{{title}}</h1><div class='body'>{{body}}</div></div>{{/prettify}}";
var templater = handlebars.compile(templateHtml);
var transformedHtml = templater({
    title: "Hello World",
    body: "De kat krabt de krullen van de trap"
});
console.log(transformedHtml);

But I get an empty result. What am I missing here? If I remove {{#prettify} and {{/prettify}} it works (but it is not pretty-printed!)

@doowb
Copy link
Member

doowb commented Jun 11, 2014

I posted an answer on stackoverflow, but I'll put it here too:

This helper was built to be used in assemble so there's a register method that needs to be called to work:

    var handlebars = require("handlebars");
    var helpers = require('prettify');
    helpers.register(handlebars);

    var templateHtml = "{{#prettify}}<div class='entry'><h1>{{title}}</h1><div class='body'>{{body}}</div></div>{{/prettify}}";
    var templater = handlebars.compile(templateHtml);
    var transformedHtml = templater({
        title: "Hello World",
        body: "De kat krabt de krullen van de trap"
    });
    console.log(transformedHtml);

That should work. Notice that prettify returns a Handlebars.SafeString() so transformedHtml will be a javascript object unless you add more markup outside of the prettify tags. You'll see what I mean by running it with and without spaces at the beginning and ending of the templateHtml string.

@svdoever
Copy link
Author

Hi doowb, I accepted the answer on stackoverflow. Thanks! My comment on stackoverflow: Hi doowb, that did definitly do the job. Could you add this to the documentation on page github.com/helpers/handlebars-helper-prettify?

@jonschlinkert
Copy link
Member

sounds like this was resolved, thanks @doowb!

@jonschlinkert
Copy link
Member

please reopen if necessary, thanks for reporting it @svdoever

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