javascript - Node JS - Adding More pages(ejs templates) using routers -
i'm new node/ejs. need clarification on creating new routes. can integrate static html files using ejs template system in node js. routing(inserting templates using route) inside body section cannot achieved me.
my code : views/index.ejs
<!doctype html> <html lang="en"> <head> <% include ./templates/head.ejs %> </head> <body class="skin-blue"> <div class="wrapper"> <% include ./templates/header.ejs %> <section class="content"> <div class="content-section container"> <div class="row"> <% include ./contents/aboutus.ejs %> //aboutus page rendering </div> </div> </section> <% include ./templates/footer.ejs %> </div> <% include ./contents/help-popup.ejs %> <% include ./templates/jsfiles.ejs %> </body> </html>
here,obviously aboutus.ejs working inside body part. call careers.ejs clicking on link inside aboutus.ejs. header , footer should not change. how add & render careers.ejs routing?
i think expecting layout system jade. can achieved npm package ejs-locals. in instead of calling ejs file, can give body part of html.
ex : boilerplate
<!doctype html> <html> <head> <title>it's <%=who%></title> <%-scripts%> <%-stylesheets%> </head> <body> <header> <%-blocks.header%> </header> <section> <%-body -%> </section> <footer> <%-blocks.footer%> </footer> </body> </html>
aboutus.ejs:
<% layout('boilerplate') -%> <% script('foo.js') -%> <% stylesheet('foo.css') -%> <h1>i <%=what%> list </h1> <% block('header', "<p>i'm in header.</p>") -%> <% block('footer', "<p>i'm in footer.</p>") -%>
career.ejs:
<% layout('boilerplate') -%> <% script('foo.js') -%> <% stylesheet('foo.css') -%> <h1>i <%=what%> programmer in usa </h1> <% block('header', "<p>i'm in header.</p>") -%> <% block('footer', "<p>i'm in footer.</p>") -%>
so, in can include other templates using ejs-locals.
Comments
Post a Comment