content.getClosest(query)

Continuing the discussion from getParentComponent:

Lets say I want to get the closest parent of page, which is using a specific template, instead of doing multiple queries by path it would be nice if I could do something like:

content.getClosest({
query: ‘page.template=templateId’
});

I guess if count > 1 one could get all ancestors ordered by “level”

Queries are dead fast and this can be implemented by anyone in a few lines doing iterative queries.
We want to keep our API as clean as possible so this is not likely to be included in the content API.

Yup. Pretty much how I solved it. Except only with one query. I generated a list of all parent paths and did query: “’_path’ in (list)”

1 Like