handlebars lekcja 1

This commit is contained in:
aplikacje committed 2026-10-08 10:51:15 +02:00
1 parent e42104c4fb
commit 527e0a34bb
1265 files changed
+213278

No files matched your search

+35
View File
@@ -0,0 +1,35 @@
const express = require("express")
const app = express()
const PORT = 3000
const path = require('path')
const { create } = require('express-handlebars');
const hbs = create({
defaultLayout: 'main.hbs', // Domyślny layout: views/layouts/main.hbs
extname: '.hbs' // rozszerzenie plików szablonów
});
app.engine('.hbs', hbs.engine); // określenie silnika szablonów
app.set('view engine', '.hbs');
app.set('views', path.join(__dirname, 'views')); // ustalamy katalog views
const context = {
subject: "ćwiczenie 3 - dane z tablicy obiektów",
books: [
{ title: "Lalka", author: "B Prus", lang: "PL" },
{ title: "Hamlet", author: "W Szekspir", lang: "ENG" },
{ title: "Pan Wołodyjowski", author: "H Sienkiewicz", lang: "PL" },
{ title: "Homo Deus", author: "Yuval Noah Harari", lang: "CZ" }
]
}
app.get("/", function (req, res) {
res.render('index03.hbs', context)
})
app.use(express.static("static"))
app.listen(PORT, function () {
console.log("start serwera na porcie " + PORT)
})