Skip to content

Find index of a page within a collection of pages #13589

Open
@c-f-h

Description

@c-f-h

If I have a collection of pages, say all pages in the current category or another taxonomy, I would like to find the numerical index of a specific page (usually, the current page).

This would be useful for outputting something like "this post is k out of n in the series on..."

I guess I could write a linear search using templates, but it seems really clunky and inefficient. Maybe there should be an .IndexOf method on the Pages object?

Example of intended use:

{{- $pages := where site.RegularPages "Params.categories" "intersect" .Params.categories -}}
{{- $currentIndex := indexOf $pages . -}}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions