Search code examples
node.jsexpresshandlebars.jsexpress-handlebarsglitch-framework

Partials not working with Express, express-handlebars


This is the file directory and server.js and a preview of what the website looks like with the error

I was excpeting the partial to show up as the header and the partial code is this `

<header>
  <a href="/">Home</a>
  <ul>
    <li><a href="/upload">upload</a></li>
    <li><a href="/library">Library</a></li>
  </ul>

</header>

`

along with this I call the partial from my template and I call it here.

`

<body>
    
    {{> header}}
    
    {{{body}}}
    
    
  </body>

` My template works just fine and switching pages works fine to I just cant get the partial to work.

I have tried changing the file name, tried all diffrent file paths, printed the file path. (it was the right file path) I have also tried all the solutions I could find on here and took a look at the docs. I have double checked my code and file path with a 3 tutorials on youtube all of them are the same as what I have. None of these changed the output any help is greatly appreciated.


Solution

  • for anyone who ever comes across this problem for me it was forgetting the extname: "hbs"

      "hbs",
      hbs.engine({
        defaultLayout: __dirname + "/views/layouts/index.hbs",
        layoutsDir: path.join(__dirname, "../views/layouts"),
        partialsDir: path.join(__dirname,  "/views/partials"),
        extname: "hbs"
    
      })
    );