Home > database >  NodeJS route title. What is it there for?
NodeJS route title. What is it there for?

Time:08-31

Please forgive my ignorance. This is such a basic question I'm almost too embarrassed to ask it, but perhaps it will help some other ignoramus down the line.

In my route:

router.get('/my-page'
  , function (req, res) {
    res.render('my-page', { title: 'some page' });
  }
);

What is the title 'some page' for?

I don't think there's a HTTP Response title header, so i'm assuming it's not for that...

Does it simply set a default HTML title element, in case you don't add a title element in your HTML?

Which would imply that the route renderer checks if you added a title?

Is it necessary to include the { title: 'some page' }

Am I asking a question that I could probably get answered with 2 minutes of playing around. Yes.

Do I want you to link me to some NodeJS/express documentation? No.

Thanks <3

#ignoramusesunite

CodePudding user response:

This is just a piece of data that you can use inside your HTML page however you like.

In your case, I assume you are using ejs

So you can open you ejs file and add

<%= title %>

Anywhere in your file and the title value that you passed will show!

So long story short, just a piece of data passed to your ejs file

CodePudding user response:

This is the documentation i was (not) looking for. Silly me

https://developer.mozilla.org/en-US/docs/Learn/Server-side/Express_Nodejs/Introduction#rendering_data_views

  • Related