Sunday 28 January 2018

Best way to organize/template ejs

HelloI have a typical page layout with a sidebar with links on the left, and a big content area on the right (no header/footer). The page is called home.ejs.What is the best way to set up the routes and templates? Ideally, when I click on a link on the sidebar, the content area should change to reflect the desired content while the sidebar remains the same, since it is essentially a navigation tool that will not change.What I tried is to have every link in the sidebar point to a route. For example, on of the links is Preferences which has a route of /preferences attached. I also created a partial called preferences.ejs which has all the content that I need. My thought was to have a route that looks like this:app.get('/preferences', function(req, res) { res.render('home', { pageContent: '<% include ./partials/preferences %>' }); }); And my main ejs file (home.ejs) that has the sidebar would also have something like this somewhere in it:
<%= pageContent %>
Note: I am a noob at this and this is just me trying to stitch some concepts together that may or may not be related. Needless to say, this doesn't work as I thought it would. What are the best ways to achieve this? Essentially, I want the sidebar to be consistent for every page, while the content is dynamic based on the click actions. Am I going about this all wrong? Would I be better off just putting the sidebar code in another partial and having one page per sidebar link?

Submitted January 28, 2018 at 08:55PM by explicitspirit

No comments:

Post a Comment