gulp-assemble icon indicating copy to clipboard operation
gulp-assemble copied to clipboard

Pages not rendering in {{#each pages }} in gulp-assemble & 0.6.0

Open brandonmerritt opened this issue 9 years ago • 8 comments

I am trying to gather up all my pages and output them as a unordered list.

{{#each pages }}
<li>{{basename }}</li>
{{/each}}

I thought I was following 0.6.0 methodology by defining my pages in my task:

gulp.task('assemble', function () {
    assemble.pages('./src/hbs/components/**/*.hbs');
    assemble.layouts('./templates/layouts/*.hbs');
    assemble.option({
        layout: 'default'
    });

    gulp.src(paths.sources.pages)
        .pipe(gulpAssemble(assemble))
        .pipe(prettify())
        .pipe(extname())
        .pipe(gulp.dest(paths.build.www));
});

I've tried a few diff variations, but I'm not getting anywhere. Can you point me to a project or provide some feedback re: what might need to change?

brandonmerritt avatar Apr 27 '15 14:04 brandonmerritt

where does paths.src.pages come from? also, assemble.pages is a method that loads templates (not vinyl files) onto assemble.views.pages.

jonschlinkert avatar Apr 27 '15 15:04 jonschlinkert

I'm defining the paths.sources.pages like this:

var paths = {
    sources: {
        pages: './src/hbs/components/**/*.hbs'
    },
    build: {
        www: './dist'
    }
};

Where the .hbs are my source pages. I think there's something basic I'm missing.

brandonmerritt avatar Apr 27 '15 15:04 brandonmerritt

yeah, you don't need to define the pages using .pages(), just pass the path to .src(). If you also want to load templates in addition to what's defined on src, you can use the assemble-push plugin.

jonschlinkert avatar Apr 27 '15 16:04 jonschlinkert

Based on your feedback I've:

Removed

 assemble.pages('./src/hbs/components/**/*.hbs');

Added the path directly to source

gulp.task('assemble', function () {
    assemble.layouts('./templates/layouts/*.hbs');
    assemble.option({
        layout: 'default'
    });

    gulp.src('./src/hbs/components/**/*.hbs')
        .pipe(gulpAssemble(assemble))
        .pipe(prettify())
        .pipe(extname())
        .pipe(gulp.dest(paths.build.www));
});

and my template still looks like:

{{#each pages }}
<li>{{basename }}</li>
{{/each}}

The each is still not working. The each statement is in my default template.

There is another open issue with this exact issue. Is there a folder structure convention that we need to stick with? If not, where is "pages" (as used by the #each statement) getting defined?

Sorry for being obtuse, but I feel like once I understand what I"m missing I'll be able to do more with Assemble.

brandonmerritt avatar Apr 27 '15 17:04 brandonmerritt

sorry, the v0.6.0 assemble v0.6.0 docs haven't been updated or published, it looks like you might be using the v0.4.x docs which won't work exactly as you expect here. That said, this is probably a better question for stackoverflow, since it's more suited for user-focused questions.

If not, where is "pages" (as used by the #each statement) getting defined?

try using the {{log this}} or {{debug this}} helpers inside your templates. use them inside and outside of the each blocks to see what's on the context. this is a great way to get the hang of how handlebars context works, and it shows you what's on the assemble object. also, assemble puts pages (and all templates) on the views object. so if you see a views object on the context, just specify the collection you want and loop over the templates in the collection (if you do {{debug this}} or {{log this}} hopefully this will make more sense)

There is another open issue with this exact issue

would you mind adding a crosslink so we can reference if needed?

jonschlinkert avatar Apr 27 '15 17:04 jonschlinkert

It's issue https://github.com/assemble/gulp-assemble/issues/16 I didn't consider that StackOverflow might address 0.6.0 issues. As long as you feel that this is a learning issue and not a bug go ahead and close this out and I'll move over there! Thanks again!

brandonmerritt avatar Apr 27 '15 17:04 brandonmerritt

didn't consider that StackOverflow might address 0.6.0 issues.

It's definitely not a bug :)

jonschlinkert avatar Apr 27 '15 17:04 jonschlinkert

For the sake of completeness here is the Stack Overflow Question re: this issue: http://stackoverflow.com/questions/29905336/each-pages-not-working-in-assemble-0-6-0-gulp-assemble

brandonmerritt avatar Apr 27 '15 20:04 brandonmerritt