Using same layout for different pages
lubomirblazekcz opened this issue · comments
Hello,
I'm currently using gulp-compile-handlebars and I'm looking for alternative, the thing I want to, is using same layout for different pages. Example:
<html class="no-js" lang="en">
{{> "layout/head"}}
<body class="preload">
<div id="body">
{{> "layout/header"}}
<main id="page">
{{> "_core/template"}}
</main>
{{> "layout/footer"}}
</div>
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.2.0/jquery.min.js" defer></script>
{{#each js as |url|}}
<script type="text/javascript" src="{{url}}" defer></script>
{{/each}}
</body>
</html>
Where _{{> "core/template"}} should be dynamic and rendering different partials per pages. Eg. homepage would render partials - slider, images, boxes and otherpage would render partials - text, form, info. I want to load dynamic partials per page and define all this in data .json file.
I want to avoid a big .hbs file where I have 20 if's on different pages with hundred of partials, I want to move all this into json file. Eg.: (this is how I have it now and if there 20 pages, it's a mess)
{{#if page_home}}
{{> "partial/slider"}}
{{> "partial/images"}}
{{> "partial/boxes"}}
{{else if page_otherpage}}
{{> "partial/text"}}
{{> "partial/form"}}
{{> "partial/info"}}
{{else if page_otherpage2}}
{{> "partial/text"}}
{{> "partial/form"}}
{{> "partial/info"}}
{{else if page_otherpage3}}
{{> "partial/text"}}
{{> "partial/form"}}
{{> "partial/info"}}
{{/if}}
Is this something that is already possible to do with gulp-hb with handlebars-layouts? If so, could you give me a little example? When I was looking for alternative I've found the gulp-hb and assemble, so I'm wondering what would be the best option here.
Any help appreciated!
You can absolutely do that with gulp-hb
and handlebars-layouts
. I did something very similar to that recently for a styleguide:
I'll try to get you a more complete example tonight or tomrrow, but it's basically using the // Advanced
example from the README
plus the front-matter
example a little further down.
Or so:
pages/about.hbs
layouts/base.hbs
The helper 'contains' is sort of https://github.com/assemble/handlebars-helpers/blob/master/lib/helpers/helpers-comparisons.js#L16
thanks for the tips! I will be switching from gulp-compile-handlebars to gulp-hb in the near future, so this really helps!
@evromalarkey Were you able to get this working, or did you still want a more complete example?
Marking as closed for now. Feel free to reopen.