Illuminatiiiiii
9/3/2018 - 8:13 PM

More EJS

Episode 6 of the Node.js and Express Tutorial series. Video:

<!DOCTYPE html>
<html lang="en">
    <head>
        <title>Game List</title>
    </head>
    <body>
        <h1>This is all of the games we have:</h1>


    <% for(var i = 0;i < gamesList.length; i++){ %>
        <div style="border-style: solid; padding: 5px; margin: 50px; max-width: 200px">
            <h4 style="color: blue">Game: <%= gamesList[i].title %></h4>
            <h5 style="color: red">Game Creator: <%= gamesList[i].creator %></h5>
        </div>
    <% } %>
    </body>
</html>
<!DOCTYPE html>
<html lang="en">
    <head>
        <title>Game Page</title>
    </head>
    <body>
        <h2>Game Title: <%= title %></h2>
        <h3>Game Creator: <%= creator %></h3>
        <!-- Only add the = when you want to display the value of a variable in ejs -->
        <!-- Our If Statement -->
        <% if(title == "Fortnite"){ %> 
            <p>Description: Fortnite Battle Royale is the FREE 100-player PvP mode in Fortnite. One giant map. A battle bus. Fortnite building skills and destructible environments combined ...</p>
        <% }else{ %>
            <p>There is no description for this game. Try Fortnite.</p>
        <% } %>
    </body> 
</html>
const express = require("express");
const app = express();

app.get("/", function(req, res){
    res.render("homepage.ejs"); 
});

app.get("/game/:gameTitle/:gameCreator", function(req, res){
    const title = req.params.gameTitle;
    const creator = req.params.gameCreator;
    res.render("game.ejs", {
        title: title,
        creator: creator
    });
});

app.get("/gamelist", function(req, res){ //Will list all of our games

    //An array of objects that holds all our games. Basically a database.
    const games = [
        {title: "Fortnite", creator: "Epic Games"},
        {title: "Dirty Bomb", creator: "Splash Damage"},
        {title: "Battlefield 1", creator: "EA"}
    ]

    res.render("gamelist.ejs", {
        gamesList: games //we send the array to the gamelist.ejs page
    });
});

app.listen("3000", function(){
    console.log("Gaming Website has started up! Made by Illuminati Productions.");
});