branquito
branquito

Reputation: 4044

generate subpages from template in jekyll

Is it possible to have a template in Jekyll, that will be filled for each subpage of a certain category with different data..

Say I have portfolio page, then I link to my works from there, each separate work page is using the same template, just the text and pics are changing.

So what I would like to have is portfolio/work1, portfolio/work2 generated from the same template and then I would iterate over _data yml files to fill in details for each work...

Is that possible in Jekyll? I couldn't find any articles on that topic.

Upvotes: 3

Views: 3092

Answers (2)

j-mes
j-mes

Reputation: 273

This can be done with 'Collections' which is a function in Jekyll. See Jekyll Collections. If you are not sure what Collections is for then maybe Ben Balter's explanation could help.

In your situation: You want a portfolio page with subpages for each piece of work. Create a collection named Portfolio in your _config.yml like below:

# Collections
collections:
  portfolio:
    output: true

Then create a folder called _portfolio in your jekyll files. You then can clarify in your front matter on each piece of work i.e. work1.md inside _portfolio which could display images, tags etc along with content like you would write a post in Jekyll. In your front-matter for each work example, you can define what template/layout you would want to use for the work examples.

Upvotes: 2

David Jacquel
David Jacquel

Reputation: 52809

You can use default setup for your portofolio folder.

1. In _config.yml, set :
defaults:
  -
    scope:
      path: "portofolio"
      type: "pages"
    values:
      layout: "work"
2. Create a _layouts/work.html template.

_

3. In your portofolio/indexhtml page

If you want to override layout, just do :

---
layout: page
...
---

Upvotes: 3

Related Questions