# Range first 4 posts that matches the first value inside the Param's array

**URL:** <https://discourse.gohugo.io/t/range-first-4-posts-that-matches-the-first-value-inside-the-params-array/24298>\
**Category:** support\
**Created:** [March 28, 2020, 1:31pm UTC](https://discourse.gohugo.io/t/range-first-4-posts-that-matches-the-first-value-inside-the-params-array/24298 "2020-03-28T13:31:33Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![dandanx](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/dandanx/32/8082_2.png) [@dandanx](https://discourse.gohugo.io/u/dandanx)\
**Post date:** [March 28, 2020, 1:31pm UTC](https://discourse.gohugo.io/t/range-first-4-posts-that-matches-the-first-value-inside-the-params-array/24298/1 "2020-03-28T13:31:33Z")

</div>

Hi there,

I have a portfolio single template, that would like to render the first 4 related portfolio with the first value of the **industry** which is `health`.

Given inside:

```
# content/works/work-1.md
industry: ["health", "lifestyle"]
# content/works/work-2.md
industry: ["health", "food"]
# content/works/work-3.md
industry: ["health", "retail"]
# content/works/work-4.md
industry: ["health"]

```

HTML inside `layouts/work/single.html`:

```
<div class="stories-list masonry stories-new">
{{$industryCat := index (.Site.Params.industry) 0 }}
{{ range first 4 (where .Site.RegularPages "Section" "works") $industryCat }}
  <div class="story-item grid-item blue">
    <div class="img">
      <img src="uploads/img29.jpg" alt="image description">
    </div>
    <h3><a href="#">Title</a></h3>
    <p><a href="#">Description</a></p>
    <ul class="categories">
      <li><a href="#">Health</a></li>
    </ul>
  </div>
{{ end }}
</div>

```

Thank you

---

<div class="post-metadata">

**Author:** ![regis](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/regis/32/4958_2.png) [@regis](https://discourse.gohugo.io/u/regis)\
**Post date:** [March 28, 2020, 3:38pm UTC](https://discourse.gohugo.io/t/range-first-4-posts-that-matches-the-first-value-inside-the-params-array/24298/2 "2020-03-28T15:38:51Z")

</div>

There’s no `where` statement that will allow you to do that. You will have to range on your posts and select the one you want:

```auto
{{ $selected := slice }}
{{ range $entry := where .Site.RegularPages "Section" "works" }}
  {{ with .Params.industry }}
    {{ if eq (index . 0) "health" }}
       {{ $selected = $selected | append $entry }}
    {{ end }}
  {{ end }}
{{ end}}

```

1. Initiate `$selected` an empty slice.
2. Store the entry at cursor as `$entry` (same as `{{ range $entries}} {{ $entry := . }}...`
3. Check if `.Params.industry` is set
4. Check if first item of `.Params.industry` is “health”.
5. Append the entry to your list of selected…
6. Use `$selected` as you wish, with `first 4 $selected` or else…  
🎉
