I
I
InfoLabs2017-07-28 15:50:59
JavaScript
InfoLabs, 2017-07-28 15:50:59

How to include mixins in a template?

Hello, there is a function that connects pug templates:

let yua_func = function(path, params) {
   return pug.renderFile(path, params); 
};

Inside each template, you need to include another pug file that contains mixins. Connecting them individually in each template is not an option. I just could not find information on how to do this at the nodejs level?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Konstantin Kitmanov, 2017-07-28
@k12th

There is none out of the box. You can try to work around it like this:

const includeMixins = 'include path/to/mixins.pug\n'; // тут можно написать много инклюдов

function yua_func(path, params, cb) {
    fs.readFile(path, (err, file) => {
        const template = includeMixins + file.toString();
        cb(pug.compile(template, params));
    });
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question