sagold / handlebars-webpack-plugin

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

Partial Contexts #4

Closed christian4423 closed 8 years ago

christian4423 commented 8 years ago

in my config I have the following:

new HandlebarsPlugin({
            // path to main hbs template 
            entry: path.join(process.cwd(), "src","handlebars","index.hbs"),
            // filepath to result 
            output: path.join(process.cwd(), "public", "index.html"),
            // data passed to main hbs template: `main-template(data)` 
            data: require("./src/data/project.json"),

            // globbed path to partials, where folder/filename is unique 
            partials: [
                path.join(process.cwd(),  "src","handlebars","components", "*", "*.hbs")
            ]
        })

I have my src folder as follows: ./src

./src/handlebars ./src/handlebars/index.hbs

./src/handlebars/components ./src/handlebars/components/title ./src/handlebars/components/title/index.hbs ./src/handlebars/components/title/data.json

In my main index.hbs file, I call the partial like this: {{> title/index data}}

It does not grab the data inside my base data.json file in the same folder as it. How do I include the context in the partial?

I was able to get it to work when used {{> title/index}} and had a title key/value in the project.json file

sagold commented 8 years ago

Hi.

Checked your data path?

// data passed to main hbs template: `main-template(data)` 
data: require("./src/data/project.json")

should point to your data.json. If i remember correctly a message should be printed on compile time. On the handlebars side this plugin does not touch a thing.

I hope this helps.