I need to dynamically add a header and footer to HTML in Node.js but I'm not sure how to do it. I have a function that takes html as a string and options that may or may not contain extra strings for header and footer content.
The idea is that if either a header or footer is passed into the function it will be appended to the existing HTML appropriately.
Here is what the function looks like. I am using lodash to test if there is header/footer content. I'd like to perform the append inside the if
block. I've had a look at cheerio but not sure if it can be used on html if it's in a string.Thanks for any help in advance!
function generator(html, options) {
var header = _.get(options, 'partials.header');
var footer = _.get(options, 'partials.footer');
// Check if either header of footer options.partials
if(header || footer) {
console.log('YEAH! ::: ', header);
// Append header and/or footer to the HTML here
}
}
via mikeym
No comments:
Post a Comment