Answer the question
In order to leave comments, you need to log in
How to use multiple express layouts?
How to use multiple templates for a site?
For example, use the first template for registration and logging into the account, and the other template for the main part of the site.
const path = require("path")
const express = require("express")
const session = require("express-session")
const bodyParser = require("body-parser")
const expressLayouts = require("express-ejs-layouts")
const mysqlConnection = require("./models/database")
const authenticateController = require("./controllers/authenticate-controller")
const registerController = require("./controllers/register-controller")
const app = express()
app.set('views', __dirname + '/views/layouts');
app.set("view engine", "ejs")
app.use(express.static(path.join(__dirname, 'views')));
app.use(expressLayouts)
app.use(session({
secret: 'secret',
resave: true,
saveUninitialized: true
}));
app.use(bodyParser.urlencoded({extended : true}));
app.use(bodyParser.json());
app.get('/', (request, response) => {
response.render('../partials/login')
})
app.get('/registration', (request, response) => {
response.render('../partials/registration')
})
app.get('/feed', (request, response) => {
response.render('../partials/feed', { expressLayouts: 'main.ejs' })
})
app.post('/auth/register', registerController.register)
app.post('/auth/authenticate', authenticateController.authenticate)
app.listen(3000)
Answer the question
In order to leave comments, you need to log in
How would I do it. On the example of authorization.
There is such data in the database.
email:""
password:""
role:""
if(res.result.role === "admin"){
response.render('../partials/news/admin')
}else{
response.render('../partials/news/user')
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question