A very interesting question has appeared - is it possible to call functions from gulpfile in jade templates?

For example. We have a hello(text) function, it simply prints the value of the passed parameter to the console. The point is to access this function from the template.

Something like this:

 +someBlock hello('It\'s alive!') +someBlock 

Accordingly, when the execution of the task reaches the rendering of the jade, in the console we will see It's alive! .

It is very important that rendering should be done via the gulp-jade plugin, not the jade.

  • In any case, I’ll notify you that Jade has been renamed Pug due to legal issues. You might want to upgrade: R - D-side
  • I haven’t heard about such a plugin, but you can make your own - find a search for the desired function, cut out the parameters and execute. - Vladimir Gamalyan
  • On the pug account - posted :) - lamartire

1 answer 1

Can. Like that:

 gulp.task('views', function() { var languages = ['en', 'ru']; i18n.init({ keyseparator: '::', supportedLngs: languages, fallbackLng: languages[0], detectLngFromPath: 0, //forceDetectLngFromPath: true, lng: languages[0], debug: true }, function() { languages.forEach(function(lang) { i18n.setLng(lang, function() { var testimonialsRaw = fs.readFileSync('./locales/comments/' + lang + '/testimonials.json', 'utf8'), testimonials = JSON.parse(testimonialsRaw), dateNow = new Date(), htmlFilePath = path.join(__dirname + '/public/index_' + lang + '.html'), // Render Pug to HTML templateHtml = pug.renderFile('./views/index.pug', { testimonials: testimonials, currentYear: dateNow.getFullYear(), t: i18n.t, i18n: i18n }); fs.writeFileSync(htmlFilePath, templateHtml); }); }); }); });