Append HTML From File With Cheerio, NodeJs
I am trying to append some html from a file to some existing html with cheerio but i keep getting errors (the errors are being produced by the cheerio library so debugging is hard)
Solution 1:
I'v worked it out. I assume someone else may run into this issue as i could see it being a common need. so here is the answer.
You need to specify that you want it returned as a string instaed of a buffer. do this with 'utf8'
expo.includeNav = function(html, result)
{
var file = 'templates/admin_nav.html';
fs.readFile(file, 'utf8', function(err, nav)
{
var $ = cheerio.load(html);
$('body').append(nav);
result($.html());
});
}
Post a Comment for "Append HTML From File With Cheerio, NodeJs"