How to use the renderFile function from pug
Find comprehensive JavaScript pug.renderFile code examples handpicked from public code repositorys.
pug.renderFile compiles a Pug template to HTML string using data object as input.
GitHub: pugjs/pug-en
296 297 298 299 300 301 302 303 304 305
``` ```js var pug = require('pug'); var html = pug.renderFile('path/to/file.pug', options); // ... ``` ## Properties
+ 3 other calls in file
GitHub: TheFive/osmbc
361 362 363 364 365 366 367 368 369 370
layout: res.rendervar.layout, article: article, vote: vote }; pug.renderFile(path.resolve(__dirname, "..", "views", "voteLabel.pug"), rendervars, function(err, result) { if (err) logger.error(err); if (err) return next(err); const v = {}; v["#vote_" + voteName + "_" + article.id] = result;
+ 31 other calls in file
How does pug.renderFile work?
pug.renderFile is a function in the Pug template engine library for Node.js that allows a Pug file to be compiled to HTML and rendered as a string. It takes a file path or a template string and options as arguments and returns a Promise that resolves with the resulting HTML string. The options can be used to customize the behavior of the Pug compiler, such as setting the template's data or changing the file's path.
72 73 74 75 76 77 78 79 80 81 82
const mailForgotPassword = (user, req, resetToken) => { const url = `${req.protocol}://${req.get( 'host' )}/api/v1/auth/reset-password/${resetToken}`; const html = pug.renderFile(`${__dirname}/../views/email/passwordReset.pug`, { url, username: user.name, });
+ 5 other calls in file
GitHub: eluv-io/elv-ramdoc
494 495 496 497 498 499 500 501 502 503
opts, packageJSON } const templateFileIndex = Path.resolve(__dirname, 'pug', 'index.pug') const outputContentIndex = pug.renderFile(templateFileIndex, context) const outputFileIndex = Path.resolve(opts.destination, 'index.html') fs.writeFileSync(outputFileIndex, outputContentIndex, {encoding: 'utf8'}) const templateFileAPI = Path.resolve(__dirname,'pug', 'api.pug')
Ai Example
1 2 3 4 5 6
const pug = require("pug"); const compiledFunction = pug.compileFile("index.pug"); const html = compiledFunction({ name: "world" }); console.log(html);
Assuming index.pug contained the following Pug markup: less Copy code
GitHub: vicmortelmans/wiezen
33 34 35 36 37 38 39 40 41 42
let global_status = SPEL_AANMELDEND function scherm_sturen() { for (const p of clients) { let message = {} if (p.status === WACHTEND) { message.htmlFragment = pug.renderFile("views/wachtend.pug", { aantal: aantal, naam: p.naam, clients: clients.filter(p => p.naam) })
+ 7 other calls in file
GitHub: vicmortelmans/wiezen
82 83 84 85 86 87 88 89 90 91
else if (p.status === GEKICKT) { message.htmlFragment = pug.renderFile("views/gekick.pug") } else if (p.status === SPELEND){ playerNamesSpelend = rotate_players(p.naam, playerNames ) message.htmlFragment = pug.renderFile("views/spelend.pug", { speler1: playerNamesSpelend[1], speler2: playerNamesSpelend[2], speler3: playerNamesSpelend[3], })
+ 161 other calls in file
GitHub: TusksAndTasks/strapi
9 10 11 12 13 14 15 16 17 18 19
}; function routeHandlers(req, dynamicPartsConfig) { return Promise.all( dynamicPartsConfig.map(({ renderFilePath, handler }) => handler(req, options => pug.renderFile(getPugFileFullPath(renderFilePath), options)), ), ); }
+ 3 other calls in file
48 49 50 51 52 53 54 55 56 57
// this host will be used for sending the account verification link to the user // when the user registers const localHost = process.env.host; // this will render the html placing the link and host wherever specified const render = pug.renderFile(__dirname + "/templates/verify_email.pug", { link: `${localHost}/api/v1/auth/token/verify?t=${token}`, host: localHost, name: name.replace("undefined", ""), });
+ 20 other calls in file
GitHub: serpconnect/website
25 26 27 28 29 30 31 32 33 34
+ '.html' ioutil.log('pugc', src, '-->', dst) var env = prodMode ? "prod" : "dev" ioutil.writeFile(dst, pug.renderFile(src, { filename: src, env: env, settings: config }))
137 138 139 140 141 142 143 144 145
meta: { pugConfig } }); let html = pug.renderFile( path.join(__dirname, '../email-templates', 'purchase-receipt.pug'), pugConfig );
+ 2 other calls in file
52 53 54 55 56 57 58 59 60 61
let mailOptions = { from: "NeoB 👻 <" + mailAccount.USER + mailAccount.DOMAIN + ">", // sender address to: mailCostumer.mail, // list of receivers subject: "Reserva", // Subject line text: "Reserva", // plain text body html: pug.renderFile(__dirname+'/../views/reservation_mail_template.pug', {imgBiblioteca: foto, biblioteca: nombre, nombre: mailCostumer.name, fecha: mailCostumer.date , sitio: mailCostumer.seat, hIni:mailCostumer.hour.split("-")[0], hFin: mailCostumer.hour.split("-")[1], hashId:hashedReservation,urlConfirmar: process.env.URL_BOTON_CONFIRMAR
+ 5 other calls in file
pug.compileFile is the most popular function in pug (496 examples)