Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Yes. You can build a function to be executed at loading time (i.e. at the <code>app</code> declarations in express), which will compile all your templates and leave them in memory:</p> <p>Take this as an example:</p> <pre><code>/** * @param {Object} app * * @api private * * @summary Compiles the partial dashboard templates into memory * enabling the admin controller to send partial HTMLs */ function compileJadeTemplates (app) { var templatesDir = path.resolve( app.get('views') , 'partials' ); var templateFiles , fn , compiledTemplates = {}; try { templateFiles = fs.readdirSync(templatesDir); for (var i in templateFiles) { fn = jade.compile( fs.readFileSync(path.resolve(templatesDir, templateFiles[i]))); compiledTemplates[templateFiles[i]] = fn; } app.set('dashboard-templates', compiledTemplates); } catch (e) { console.log('ERROR'); console.log('---------------------------------------'); console.log(e); throw 'Error on reading dashboard partials directory!'; } return app; } </code></pre> <p>Calling the templates in an expressJS controller function this way:</p> <pre><code>/** * @param {String} req * @param {Object} res * @param {Object} next * * @api public * * @url GET /admin/dashboard/user_new * * @summary Returns HTML via AJAX for user creation */ controller.newUser = function (req, res, next) { var compiledTemplates = app.get('dashboard-templates'); var html = compiledTemplates['_user_new.jade']({ csrf : req.session._csrf}); return res.send({ status : 'OK', message : html}); } </code></pre> <p>In this case, I'm sending the <code>html</code> via AJAX; to be appended by the application. In the event that you don't want to do that. You can send the html with these functions:</p> <pre><code>res.write(html); return res.end(); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload