Complete the code to render a view using a layout in Express with EJS.
app.get('/', (req, res) => { res.render('index', { layout: '[1]' }); });
The layout option specifies which layout file to use when rendering the view. 'main-layout' is a common default name.
Complete the EJS code to include a partial header template inside a layout.
<header>
<%- include([1]) %>
</header>The include statement inserts the content of the specified partial file. Here, the header partial is included.
Fix the error in the EJS layout to correctly render the body content.
<body>
[1]
</body>Using <%- body %> outputs unescaped HTML content, which is needed to render the body correctly in layouts.
Fill both blanks to create a layout that includes a header partial and renders the body content.
<html>
<body>
<header>
<%- include([1]) %>
</header>
<main>
[2]
</main>
</body>
</html>The header partial is included with include('partials/header.ejs'). The body content is rendered unescaped with <%- body %>.
Fill all three blanks to create an Express route that renders a view with a layout and includes a footer partial in the layout.
app.get('/about', (req, res) => { res.render('about', { layout: [1] }); }); // In layout file: <footer> <%- include([2]) %> </footer> // In about.ejs: <h1>[3]</h1>
The route renders 'about' view with 'main-layout'. The layout includes the footer partial. The about view shows the heading 'About Us'.