{"id":550,"date":"2022-08-30T15:03:13","date_gmt":"2022-08-30T15:03:13","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/11\/09\/is-there-a-way-to-add-css-js-later-using-ejs-with-nodejs-express-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:03:13","modified_gmt":"2022-08-30T15:03:13","slug":"is-there-a-way-to-add-css-js-later-using-ejs-with-nodejs-express-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/is-there-a-way-to-add-css-js-later-using-ejs-with-nodejs-express-collection-of-common-programming-errors\/","title":{"rendered":"is there a way to add CSS\/JS later using EJS with nodejs\/express-Collection of common programming errors"},"content":{"rendered":"<p>found a solution here: Node.js with Express: Importing client-side javascript using script tags in Jade views?<\/p>\n<p>it&#8217;s using jade instead of EJS but works all the same. here are some code-snippets for express 2.4.0.<\/p>\n<p>you have to add the following &#8220;helpers&#8221; to your app.js<\/p>\n<pre><code>app.helpers({\n  renderScriptsTags: function (all) {\n    if (all != undefined) {\n      return all.map(function(script) {\n        return '';\n      }).join('\\n ');\n    }\n    else {\n      return '';\n    }\n  }\n});\n\napp.dynamicHelpers({\n  scripts: function(req, res) {\n    return ['jquery-1.5.1.min.js'];\n  }\n});\n<\/code><\/pre>\n<p>the <strong>layout.ejs<\/strong> looks sth like this:<\/p>\n<pre><code>\n\n  \n    \n      \n      \n  \n  \n    \n  \n\n<\/code><\/pre>\n<p>if you don&#8217;t add any scripts to the scripts-array, only &#8216;jquery-1.5.1.min.js&#8217; will be included &#8211; if you want to add files to a subpage you can do this like so:<\/p>\n<p><strong>test.ejs<\/strong><\/p>\n<pre><code>\n\n<\/code><\/pre>\n<pre>\n<br \/>I'm a template with 3 js files in the header\n<\/pre>\n<p><code>that's it.<\/code><\/p>\n<p id=\"rop\"><small>Originally posted 2013-11-09 20:50:42. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>found a solution here: Node.js with Express: Importing client-side javascript using script tags in Jade views? it&#8217;s using jade instead of EJS but works all the same. here are some code-snippets for express 2.4.0. you have to add the following &#8220;helpers&#8221; to your app.js app.helpers({ renderScriptsTags: function (all) { if (all != undefined) { return [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-550","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/550","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=550"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/550\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=550"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=550"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=550"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}