Those options would be nice for something like this. Take into consideration that this is following my scribbled approach for routing and not the final one you will implement.
routes.json
{
"path": "/forgot",
"url": "pages/authentication/layout",
"options": {
"id": "forgot", //Pass the body id attribute value.
"content": "_forgot" // Render the content partial in the layout
}
},
route.js
if (route.url) {
app[route.method || 'get'](route.path, (req, res) => {
res.render(route.url, route.options);
});
My layout file.
<!DOCTYPE html>
<html lang="en">
<head>
<%- include ('../../partials/_head') %>
</head>
<body class="application application-offset" is="dmx-app" id=<%= id %> dmx-show="translationLoaded">
<!-- Application container -->
<div class="container-fluid container-application">
<!-- Content -->
<div class="main-content position-relative">
<!-- Page content -->
<%- include (content) %>
<!-- Footer -->
<%- include ('../../partials/footer') %>
</div>
</div>
<!-- Scripts -->
<%- include ('../../partials/_footerjs') %>
</body>
</html>
It was quite straightforward to implement a layout system. There are one or two node modules out there that implement blocks and layouts but you actually don’t need that much to implement a simple system.
1st Edit:
I know this has further implications with App Connect design panel that would need further adaptation and can’t be done without considering how to edit a partial file as an App Connect page. Similar to old SSIs.
2nd Edit:
I can’t add more than 3 consecutive replies or I will be sent to the discourse spam jail.
@patrick this is also how I implemented adding JS files from partials to the head of the layout. In case it inspires you for a better way. My implementation is quite simple and I need to double check that if I call a getScripts from another layout file it only loads scripts that pertain to that layout and not from previous.
partial
<% addScripts(['formatters.js', 'zxcvbn/4.4.2/zxcvbn.js', 'js-sha1/0.6.0/sha1.min.js']) %>
<div class="page-content">
...
layout
<head>
<%- include ('../../partials/_head') %>
<%- getScripts() %>
</head>
server.js (SO copypasta)
//Add scripts
app.locals.scripts = [];
app.locals.addScripts = function (all) {
app.locals.scripts = [];
if (all != undefined) {
app.locals.scripts = all.map(function (script) {
console.log(script);
return "<script src='/js/" + script + "'></script>";
}).join('\n ');
}
};
app.locals.getScripts = function (req, res) {
return app.locals.scripts;
};