is there a way to add CSS/JS later using EJS with nodejs/express

后端 未结 5 1306
情歌与酒
情歌与酒 2021-02-01 09:26

i\'m using the EJS template engine with nodejs/express and i\'m wondering if it\'s possible to add another css or js file in e.g the index.ejs (not the layout.ejs)

5条回答
  •  失恋的感觉
    2021-02-01 10:19

    As helpers and dynamicHelpers are gone in Express > 3, I rewrote pkyeck code so it works in Express 3.

    So in app.js have this instead of the helpers / dynamicHelpers. Leave everything else as is.

    app.locals({
        scripts: [],
      renderScriptsTags: function (all) {
        app.locals.scripts = [];
        if (all != undefined) {
          return all.map(function(script) {
            return '';
          }).join('\n ');
        }
        else {
          return '';
        }
      },
      getScripts: function(req, res) {
        return scripts;
      }
    });
    

提交回复
热议问题