avillafiorita / jekyll-datapage_gen

Generate one page per yaml record in Jekyll sites.
367 stars 79 forks source link

Documentation: How to use Jekyll category/tag in generated pages? #97

Open inetbiz opened 3 years ago

inetbiz commented 3 years ago

I am creating a product site. I need to use category/tag pages built into Jekyll. Ideas?

desirtech commented 3 years ago

Just dealt with this, try this! (Mind you Page variables like content or title are reserved by Jekyll Layouts object, maybe there should be a _templates dir?)

product.yaml

- id: Soap
  template: template
  data: The best Soap for Ever Lasting Life!
  category: home 
  tags: on-sale, organic

template.md

---
title: {{ page.id }}
layout: {{ page.template }}
category: {{ page.category }} 
tags: {{ page.tags }}
---

# {{ page.id }}

> {{ page.data }}

hope this works!

avillafiorita commented 2 years ago

First of all thanks for the report, thanks to @jeffreydesir for the feedback, and sorry for taking ages before answering your question.

Just to add my two bits, you can also use =page_data_prefix= to prefix the variables and avoid clashes with reserved words.

config.yml

- data: product
   page_data_prefix: my

product.yaml

- id: Soap
  template: template
  data: The best Soap for Ever Lasting Life!
  category: home 
  tags: on-sale, organic

template.md

---
title: {{ page.my.id }}
layout: {{ page.my.template }}
category: {{ page.my.category }} 
tags: {{ page.my.tags }}
---

# {{ page.my.id }}

> {{ page.my.data }}