Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "extends" #546

Closed
Bluzzi opened this issue Sep 16, 2020 · 5 comments
Closed

Add "extends" #546

Bluzzi opened this issue Sep 16, 2020 · 5 comments

Comments

@Bluzzi
Copy link

Bluzzi commented Sep 16, 2020

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 !

@dannyhpy
Copy link

dannyhpy commented Sep 17, 2020

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

@rivy
Copy link

rivy commented Nov 27, 2020

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.

@dannyhpy
Copy link

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.

@Bluzzi
Copy link
Author

Bluzzi commented Nov 29, 2020

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 !

@shaynlink
Copy link

Very good idea, i approve this ✔️

@Bluzzi Bluzzi closed this as completed Jan 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants