Данные, хранящиеся в массиве для экспресс-назначения, не отображаются на веб-странице на сервере и не выдают никаких ошибок, поэтому я не знаю, в чем проблема.
Я набросал несколько разных идентификаторов, чтобы увидеть, не использовал ли я правильный синтаксис, в основном, путаясь с «средней» частью кода, такой как
router.get('/:middle', function(req, res, next) {
let middle = storyline.storylines.find( part => {
return part.storyPart === req.params.storyPart;
});
res.render('middle', { middle });
index.js:
var express = require('express');
var router = express.Router();
var storyline = require('../models/storyline');
/* GET home page. */
router.get('/beginning', function(req, res, next) {
let beginning = storyline.storylines.find( part => {
return part.storyPart === "beginning";
});
res.render('beginning', { beginning });
});
router.get('/:middle', function(req, res, next) {
let middle = storyline.storylines.find( part => {
return part.storyPart === "middle";
});
res.render('middle', { middle });
});
router.get('/end', function(req, res, next) {
let end = storyline.storylines.find ( part => {
return part.storyPart === "end";
});
res.render('end', { end });
});
module.exports = router;
STORYLINE.JS:
module.exports.storylines = [
{
storyPart: "beginning",
name: "Rupert",
animal: "fox",
age: 8
},
{
storyPart: "middle",
place: "France",
travelVehicle: "train",
yearsToStay: 2
},
{
storyPart: "end",
foxWife: "Amelie",
housing: "a house next to the Eiffel Tower"
}
];```
BEGINNING.hbs:
<h1>"Once upon a time, there was a {{animal}} named {{name}}. He was only {{age}} years old, but he loved to travel.</h1>```
MIDDLE.hbs:
<h1>"One day, Rupert decided to visit {{place}}. So, he hopped on a {{travelVehicle}} to get there. Once he got there, he decided to stay for at least {{yearsToStay}} years."</h1>```
END.hbs:
<h1>"After a while, Rupert met a beautiful fox named {{foxWife}}. They fell deeply in love and lived in {{housing}}. They lived there happily ever after. The end."</h1>
hbs text loads without the information from the model in the curly brackets. No errors thrown in either VSC or the terminal on the browser.