All right. Are you ready for challenge 19? 1
All right so here's the goal of this challenge. Instead of console logging whether something matched 2
or not match, 3
we actually want to render the actual page so that if we have a post say called another post inside 4
our home page we should be able to head over to /posts/another-post. 5
And the goal of this challenge is that when I hit enter we should now get taken to a brand new page 6
that's been rendered using EJS and it's a standalone page that just contains the contents of that particular 7
blog post. 8
And if I had more than one post say if I had another post-coup Day 2 as the title, then I should be 9
able to navigate to it by simply going to /posts/day-2. And now when I hit 10
enter I get taken to another page, a brand new page for this blog post. 11
And no matter how many new posts that you compose every single one of them should dynamically get its 12
own page just by using EJS and our Express routing parameters. Inside the views folder 13
you should notice that you already have a empty file called post. 14
ejs. 15
See how you can use this along with what we've got so far 16
in order to create this outcome. Pause the video and complete the challenge. 17
Now my first hint for you is that you don't need this else statement any more. 18
You're only checking to see if the requestedTitle is equal to the storedTitle. And in that case instead 19
of console logging, you want to send people over to this posts.ejs page. And you need to render this 20
page such that it gets access to the title and the content of the post that is being requested. 21
You will need to decide on some variable names for what you want to pass over using EJS, 22
you'll have to add the layouts the header and footer just as we have done for all the other pages and 23
then you have to use the EJS tags in order to render an h1 and a paragraph tag of the title and 24
the body. 25
So see if this is enough of a hint for you to now be able to complete the challenge. 26
Now the second hnt if you need it is that remember how we rendered our home page right? 27
We actually used a method called res.render. 28
Seems like a long time ago but we use res.render and then we specify the name of the page that 29
we want to render and then we added a comma and then we specified a Javascript object where we have 30
a key and a value and the value is the thing that we want to pass over and the key is the thing that 31
we get to access inside that target page. 32
So with this final hint see if you can now complete the challenge.