Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Choose metalsmith collection from .md file #26

Closed
fracu opened this issue Dec 12, 2014 · 1 comment
Closed

Choose metalsmith collection from .md file #26

fracu opened this issue Dec 12, 2014 · 1 comment

Comments

@fracu
Copy link

fracu commented Dec 12, 2014

I've been using Metalsmith static site generator for some time and I believe is a great tool. Now I started using metalsmith-collections plugin but I stumbled across this issue.

Given the case that I have two collections defined, for instance "en_news" and "sp_news" and the following news.hbt file:

<h1>{{title}}</h1>
{{contents}}

<ul>
    {{#each collections.en_news}}
        <li>
            <h3>{{this.title}}</h3>
            <article>{{this.contents}}</article>
        </li>
    {{/each}}
</ul>

Now in the .md file I want the collection to be either collection.en_news:

---
title: News
template: news.hbt
lang-collection: en_news

---
News in english language

...or collection.sp_news:

---
title: Noticias
template: news.hbt
lang-collection: sp_news

---
News in spanish language

How can I use "lang-collection" inside test.hbt to define the used collection?

Of course the following does not work:

{{#each collections.{{lang-collection}}}}

Thanks in advance!

@GRUBES
Copy link

GRUBES commented Apr 17, 2016

@fracu I just accomplished this today using Handlebars' lookup helper:

My handlebars layout:

{{#each (lookup collections rollup)}}
  <li>
    <h3><a href="{{../relative this.path }}">{{ this.title }}</a></h3>
    {{{ this.excerpt }}}
   </li>
{{/each}}

My yaml front-matter:

---
title: Recent Articles
layout: rollup.html
rollup: recent-articles
associated-collection: articles
---

I use the rollup property from my YAML front-matter to define my dynamic collection. Then I use the Handlebars lookup helper inside a subexpression (the parens) in the #each.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants