Skip to content

group_by_exp fails with object as input #785

@theonlypwner

Description

@theonlypwner

In Jekyll, it is possible to do

{%- assign tags_by_size = site.tags | group_by_exp: 'tag', 'tag[1].size' | sort: 'name' | reverse -%}
{%- for tags_with_size in tags_by_size -%}
{%- for tag in tags_with_size.items -%}
{%- assign tag_name = tag[0] -%}
<!-- ... -->
{{ tag_name }} <sup>{{ tags_with_size.name }}</sup> <!-- tag name and count -->
<!-- ... -->
{%- for post in tag[1] %}
<!-- render each post with this tag -->
<!-- ... -->

However, in liquidjs, collections.postsByTag | group_by_exp: 'tag', 'tag[1].size' (where collections.postsByTag in Eleventy is in the same format as site.tags in Jekyll) just ends up being [ { name: undefined, items: [ [Object] ] } ]

Running collections.postsByTag through Object.entries makes this filter work properly.

This came up while migrating from Jekyll to Eleventy, but I will probably end up reimplementing this functionality, so I might not need it in the end, but I am reporting this missing functionality here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions