ejs icon indicating copy to clipboard operation
ejs copied to clipboard

Add "extends"

Open Bluzzi opened this issue 4 years ago • 5 comments

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 !

Bluzzi avatar Sep 16 '20 19:09 Bluzzi

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

dannyhpy avatar Sep 17 '20 14:09 dannyhpy

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.

rivy avatar Nov 27 '20 01:11 rivy

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.

dannyhpy avatar Nov 28 '20 23:11 dannyhpy

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 !

Bluzzi avatar Nov 29 '20 00:11 Bluzzi

Very good idea, i approve this :heavy_check_mark:

shaynlink avatar Dec 07 '20 13:12 shaynlink