Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The engine can't recognise .hbs extension with partials #251

Open
r-h36 opened this issue May 15, 2019 · 3 comments
Open

The engine can't recognise .hbs extension with partials #251

r-h36 opened this issue May 15, 2019 · 3 comments

Comments

@r-h36
Copy link

r-h36 commented May 15, 2019

Env settings:

node 10.15.1
npm 6.4.1
handlebars 4.1.2
express 4.16.4

Just updated the express-handlebars from 3.0.0 to 3.1.0
run into this issue:
server.js

const exphbs = require('express-handlebars');
const hbsHelpers = require('./config/hbsHelpers');
const hbs = exphbs.create({
    extName: '.hbs',
    partialsDir: 'views/partials/',
    layoutsDir: 'views/layouts/',
    defaultLayout: 'main.hbs',
    helpers: hbsHelpers,
});
app.set('views', path.join(__dirname, 'views'));
app.engine('.hbs', hbs.engine);
app.set('view engine', '.hbs');

app.get('/', function (req, res) {
    res.render('test.hbs');
})

The extName is defined in the config.

in test.hbs

<div class="wrapper home">
    <h1>Test Page</h1>
    
    {{> pages/nav }}
</div>

File structure

.
├── app.js
└── views
    ├── test.hbs
   └── partials
              └── pages
                        └──nav.hbs

This results in error
Error: The partial pages/nav could not be found

But if I change the nav.hbs to nav.handlebars, the error is gone.

nav.hbs used to be working fine before I update the express-handlebars to 3.1.0

@PhilHannent
Copy link

Are you sure this isn't a case sensitive issue:

extname

@noslouch
Copy link

just want to throw in here that the handlebars engine wasn't recognizing partials with .hbs until I specified it in the value passed to app.engine, even though templates were recognized just fine.

I passed in {extname: 'hbs'} to the engine factory function and it started picking up partials with an .hbs extension. This worked for me with and without a leading dot, i.e. using hbs and .hbs as the value for extname worked the same.

const express = require('express');
const hbs = require('express-handlebars');


const app = express();

// app.engine('hbs', hbs());
app.engine('hbs', hbs({ extname: 'hbs' ));
app.set('view engine', 'hbs');

@Benja1512
Copy link

const express = require('express');
const exphbs = require('express-handlebars');
const path = require('path');
const router = require('./routes');

const app = express();

// habilitar handlebarss como view

app.engine('.hbs',
exphbs.engine({
defaultLayout: 'layout'
})
);

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants