Does .Resource.ByType only work in the root or also subfolders?

Due to a question here:

I am wondering if .Resource.ByType only looks for the given type in the immediate root folder of the current page, or if it will also look in the subfolders of that page. Based on that post, it seems it’s only the root folder.

This doc page doesn’t give any indication on the scope of the function:

I believe (but haven’t tested) the issue in that case is not the .ByType but the .GetMatch

{{- $featured := $images.GetMatch "*feature*" -}}
{{- if not $featured }}{{ $featured = $images.GetMatch "{*cover*,*thumbnail*}" }}{{ end -}}

Even if .ByType returns from all subdirectories of a leaf bundle, the .GetMatch glob pattern would fail to match the directory separator (/ on *nix systems, not sure if it is normalized or not). Based on

I think **cover* is what would have the desired effect.

It looks for all matching page resources. By definition, that includes subdirectories within leaf bundles.

I see what you are saying, that’s a good point.

Thank you, good to know. Is the result then being filtered to the root folder only by the subsequent .GetMatch not using the super-asterisk?

Already answered by @cshoredaniel

Ya, just confirming that holds even though $images already has a list of all the files including subdirectories.

Thank you for the link!

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.