JGallardo
JGallardo

Reputation: 11373

How to render html into a page but not as the entire view into an Node.js + express app?

Intent
I need to render portion of hmtl into a page.

Problem
The page is being rendered without styling or layout.


I have a page that I need to be in plain html and not jade. But will still be using jade elsewhere.

I followed along to a similar question and that works to direct to an html page. BUT the styles and layout if not being passed in.

My previous page was cases.jade and started like this

extends layout

block content
  .row
    .twelve.columns
      h1 title

Now my new page is cases.html and starts like this

<div class="row">
  <div class="twelve columns">
    <h1>Before &amp; After Case Gallery</h1>

and is routed to like this

app.get('/cases', function (req, res)
{
  res.render('cases.html');
});

and has this above it

app.set('views', __dirname + '/views');
app.engine('html', require('ejs').renderFile);

Upvotes: 1

Views: 220

Answers (1)

rtpg
rtpg

Reputation: 2439

It seems like in your jade file, you're extending the layout page, so you include all your layout info. But in the HTML version you aren't importing any of the layout information.

I see you're using ejs. Check out layouts, to see what to put into your template:

<% include head %>
<h1>Title</h1>
<p>My page</p>
<% include foot %>

Here you'll want to do something like <%include layout %>, with your layout page stuff in layout.html. The include line will basically copy-paste the file's content into that spot.

Upvotes: 1

Related Questions