shannonmoeller / gulp-hb

A sane Gulp plugin to compile Handlebars templates. Useful as a static site generator.
http://npm.im/gulp-hb
MIT License
147 stars 14 forks source link

Generating multiple pages / is it possible? #72

Closed mpodciwinski closed 5 years ago

mpodciwinski commented 5 years ago

Hello, I wonder if it is possible to generate multiple subpages from one .json file.

example .json file

[
   {
      "title": "A",
      "website": "website-a.com"
   },
   {
      "title": "B",
      "website": "website-b.com"
   }
]

using .hbs template:

<!DOCTYPE html>

<body>
   <h1>{{title}}</h1>
   <span>{{website}}</span>
</body>

</html>

and render to separate .html files with custom names from data.json (for example {{title}})

├── dist
│   ├── a.html
│   ├── b.html
├── data
│   ├── data.json
├── template
│   ├── template.hbs

it is possible?

shannonmoeller commented 5 years ago

This is possible, yes. The patterns have been documented in past issues. Please have a look at those and let me know if you’re still having trouble making it work!

mpodciwinski commented 5 years ago

this is very close https://github.com/shannonmoeller/gulp-hb/issues/46#issuecomment-246763138, but i need render file from .hbs templates. How to do that?

mpodciwinski commented 5 years ago

Any ideas?

shannonmoeller commented 5 years ago

Unfortunately I don't have time to create the example code for you, but what you're trying to do is absolutely possible. You should be able to start with the code in #46 and also use lines 14-23 here:

https://github.com/shannonmoeller/tmp/blob/master/gulpfile.js