sagold / handlebars-webpack-plugin

Renders your html-template at build time
161 stars 45 forks source link

Outputting blank HTML #42

Closed Dan503 closed 5 years ago

Dan503 commented 5 years ago

Simplified config file:

module.exports = {
  ...

  plugins: [
    handlebars: new HandlebarsPlugin({
      entry: path.join(__dirname, 'pages', "*.handlebars"),
      output: path.join(__dirname, "build/[name].html"),
      partials: [
        path.join(__dirname, "modules", '**', "*.handlebars"),
        path.join(__dirname, "partials", "*.handlebars"),
      ],
    }),
  ],

  ...
}

pages/page.handlebars file:

{{#> base title="Home | RSL Queensland" }}
  {{#*inline "content-block"}}
    <p>Hello world</p>
  {{/inline}}
{{/base}}

partials/base.handlebars file:

<!DOCTYPE html>
<html lang="en">
<head>
  <title>Document</title>
</head>
<body>

    {{#> content-block}} {{!-- Page content goes here. --}} {{/content-block}}

</body>
</html>

The page.html file that is output into the build folder is completely blank. I am not seeing any errors in my console.

versions:

"handlebars-webpack-plugin": "1.5.0",
"webpack": "4.18.0",

I'm not sure if this is a bug or if I'm doing something wrong. :/

Dan503 commented 5 years ago

A coworker of mine solved the issue 😁

The partials/base.handlebars file needs to look like this:

{{#> partials/base title="Home | RSL Queensland" }}
  {{#*inline "content-block"}}
    <p>Hello world</p>
  {{/inline}}
{{/partials/base}}

Note that the closing tag needs to be /partials/base not just /base. I was only setting the opening tag to partials/base and was getting an error saying that partials/base and base don't match. The error was a bit difficult to interpret.