Using range to filter on section, tag and sort at the same time

I use this snippet on my blog overview, and that works fine:

{{ range ( where .Data.Pages.ByDate.Reverse "Section" "articles" ) }}
   <li class="blog-tile">
      {{ partial "blog-tile.html" . }}
{{ end }}

Now, I want to re-use the same snippet to promote blog posts to the homepage that have the tag ‘home’, but at the same time limit the list to 3 items being displayed at once.

I came up with this, but of course that doesn’t work, because it first filters down the list to 3 items and then checks whether the item has a tag of ‘home’:

{{ range first 3 ( where .Data.Pages.ByDate.Reverse "Section" "articles" ) }}
   {{ if ( in .Params.tags "home" ) }}
      <li class="blog-tile">
         {{ partial "blog-tile.html" . .Section }}
      </li> <!-- /.blog-title -->
   {{ end }}
{{ end }}

Now I can’t figure out how to get my ‘range’ right so it only lists pages in the section ‘articles’ and at the same time have the tag ‘home’ applied to them :frowning:

Thanks for your help!

I haven’t used this personally, but looks like the nested where clauses is what you want:

I’m not sure if this working, but you can try the following range with your tags as variable

{{ $home := .Site.Taxonomies.tags.home  }}
{{ range ($home.Pages.GroupBy "Section") }}
  	{{ if eq .Key "articles" }}
    	    {{ range last 3 .Pages.ByDate }}
    	          //-- your code here --//
 	    {{ end }}
	{{ end }}
{{ end }}