ejs
ejs copied to clipboard
Add "extends"
It would be really cool to add the possibility to extend other pages and complete blocks like this :
Base.ejs :
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title><%- block title %><%- endblock %></title>
<%- block stylesheets %><%- endblock %>
<%- block javascripts %><%- endblock %>
</head>
<body>
<%- block body %><%- endblock %>
</body>
</html>
HomePage.ejs
<%- extends "Base.ejs" %>
<%- block title "EJS" %>
<%- block body %>
<h1>Hello EJS !</h1>
<%- endblock %>
Thank you for your attention !
It already exists and it's called includes: https://ejs.co/#docs
This syntax <% if (1) { %>
is used to embed Javascript and <% block body %>
isn't Javascript at all and would result into errors
It may uses Javascript and follow this syntax to output the block content onto the page <%- block('title') %>
(<% %>
does not output anything)
Anyway, there is already a feature for that so I don't think it would be interesting
It already exists and it's called includes: https://ejs.co/#docs
That's the inverse of the request; it's not the same thing at all.
That's the inverse of the request; it's not the same thing at all.
True, it's not quite the same thing but it achieves the same goals.
Using include
, I'm doing the same thing with even less code.
head.ejs
<!DOCTYPE html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title><%= title %></title>
<%- stylesheets %>
<%- javascripts %>
</head>
homepage.ejs
<html>
<%- include('head', { title: 'EJS' }) %>
<body>
<h1>Hello EJS!</h1>
</body>
</html>
Also, it's worth mentionning that the syntax is not consistent (here, you do not have to close the « block » for some reason) and it doesn't follow the Javascript syntax as I pointed out in my previous comment.
<%- block title "EJS" %>
This « feature » is unnecessary, includes can do all of that with more consistency.
On several pages, it won't be less code. Moreover it forces to pass the title variable through another page.
For your example, it's not relevant to do this for scripts and stylesheets.
You are trying to argue for a pointless matter, it won't change anything for you if this feature is added.
In short, stop polluting this issue with a different feature, I'm waiting for an answer from @mde !
Very good idea, i approve this :heavy_check_mark: