Eleventy: How can I programmatically set tags?

Created on 22 Sep 2020  路  2Comments  路  Source: 11ty/eleventy

From the documentation, I see:

It is important to note that Computed Data is computed right before templates are rendered. Therefore Computed Data cannot be used to modify the special data properties used to configure templates (e.g. layout, pagination, tags etc.). These restrictions may be relaxed over time.

Which means this is not possible:

---
pagination:
    data: pressReleases
    size: 1
    alias: pr
    addAllPagesToCollections: true
permalink: "/newsroom/{{ pr.slug }}/"
layout: newsroom-base.liquid

eleventyComputed:
  title: "{{ pr.title }}"
  permalink: "/newsroom/{{ pr.slug }}/"
  tags: "{{ pr.category }}" // 馃様馃様馃様 
---

A way to define tags and collections for API data would be incredible.
If possible, can anyone point me in the direction on how this can be changed?

education

Most helpful comment

@araphiel I'm computing tags inside a collection creation here:
https://github.com/nhoizey/nicolas-hoizey.com/blob/master/src/_11ty/collections/notes.js

It adds hashtags found in content to the tags added via Front Matter.

Maybe it can serve as inspiration.

All 2 comments

@araphiel I'm computing tags inside a collection creation here:
https://github.com/nhoizey/nicolas-hoizey.com/blob/master/src/_11ty/collections/notes.js

It adds hashtags found in content to the tags added via Front Matter.

Maybe it can serve as inspiration.

@nhoizey This is incredibly helpful - thank you.

Was this page helpful?
0 / 5 - 0 ratings