Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

147
Visualizações
using common layout for all the pages in pug

I am trying out pug with express

views/layout.pug 

doctype html
html
  head
    title= title
    link(rel="shortcut icon", href="favicon.ico", type="image/x-icon")
    link(rel='stylesheet', href='/assets/application.css')
    link(rel='stylesheet', href="assets/libs/bootstrap/dist/css/bootstrap.min.css")
  body    
    script(src="assets/libs/jquery/dist/jquery.min.js")
    script(src='assets/libs/bootstrap/dist/js/bootstrap.min.js')
    script(src="assets/application.js")
    block content

This is the router for User page.

routes/user.js

var express = require('express');
var router = express.Router();

/* GET users listing. */
router.get('/', function(req, res, next) {
  res.render('user/index');
});

module.exports = router;

I have my view for user/index page. I extends the layout from the views. User index page using the layout. layout.pug is present in views folder.

If I add a layout.pug inside views/user it works. But how to use the views/layout.pug

/views/user/index.pug

extends layout


block content
    h1
     | User index

i get the following error. it is looking for layout in view/user folder. How to make it to use view/layout.pug.

Error: ENOENT: no such file or directory, open 'C:\my_projects\myexpressapp\views\user\layout.pug'
    at C:\my_projects\myexpressapp\views\user\index.pug line 1
    at Error (native)
    at Object.fs.openSync (fs.js:640:18)
    at Object.fs.readFileSync (fs.js:508:33)
    at Function.read (C:\my_projects\myexpressapp\node_modules\pug-load\index.js:69:13)
    at Object.read (C:\my_projects\myexpressapp\node_modules\pug\lib\index.js:147:25)
    at C:\my_projects\myexpressapp\node_modules\pug-load\index.js:24:25
    at walkAST (C:\my_projects\myexpressapp\node_modules\pug-walk\index.js:23:18)
    at C:\my_projects\myexpressapp\node_modules\pug-walk\index.js:104:20
    at Array.reduce (native)
    at walkAndMergeNodes (C:\my_projects\myexpressapp\node_modules\pug-walk\index.js:103:18)
about 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

In your app.js file, check whether you have defined the views properly.

View engine should be set to pug and views folder should be set properly as described below in app.js

app.set('view engine', 'pug');
app.set('views', path.join(__dirname, 'views'));
about 4 years ago · Santiago Trujillo Relatório

0

You have to set the baseDirectory variable.

I'm not familiar with Express, I found the answer How do you set jade basedir option in an express app? (the "basedir" option is required to use "extends" with "absolute" paths)

about 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda