# Range through content type from single template

**URL:** <https://discourse.gohugo.io/t/range-through-content-type-from-single-template/6081>\
**Category:** support\
**Created:** [April 8, 2017, 8:44pm UTC](https://discourse.gohugo.io/t/range-through-content-type-from-single-template/6081 "2017-04-08T20:44:47Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![onur](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/onur/32/2953_2.png) [@onur](https://discourse.gohugo.io/u/onur)\
**Post date:** [April 8, 2017, 8:44pm UTC](https://discourse.gohugo.io/t/range-through-content-type-from-single-template/6081/1 "2017-04-08T20:44:47Z")

</div>

Hi friends,

I’m working on a template where I have projects and lessons. A project can have multiple lessons and a one lesson could be used in two projects.

The problem I’m trying to solve is to display all lessons that belong to a project in a list. While this code works from index.html it doesn’t work from the project single.html. The scope I’m in is a projects data.

```
{{- range (where .Data.Pages "Section" "lesson") }}
{{ end }}

```

[Code](https://github.com/onurakpolat/hugo-indie-theme/commit/e73f378c5078b1d9e797da2c559d6823ec7407c6#diff-1f4aa8f46ba1586a05afbcffcf2147a8R59)

While I don’t get an error, I also don’t see any content.

What I planned to do is to have a variable lessons = [“lesson1”, “lesson2”] etc.  
I’m open to new approaches on how to solve this problem.

Cheers,  
Onur

---

<div class="post-metadata">

**Author:** ![onur](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/onur/32/2953_2.png) [@onur](https://discourse.gohugo.io/u/onur)\
**Post date:** [April 8, 2017, 8:55pm UTC](https://discourse.gohugo.io/t/range-through-content-type-from-single-template/6081/2 "2017-04-08T20:55:25Z")

</div>

Changing `Data` to `Site` gives me the lessons. Now I need to add the checks and logic to add lessons.

---

<div class="post-metadata">

**Author:** ![rdwatters](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/rdwatters/32/2848_2.png) [@rdwatters](https://discourse.gohugo.io/u/rdwatters)\
**Post date:** [April 8, 2017, 9:06pm UTC](https://discourse.gohugo.io/t/range-through-content-type-from-single-template/6081/3 "2017-04-08T21:06:46Z")

</div>

> [@onur](#):
>
> Changing Data to Site gives me the lessons. Now I need to add the checks and logic to add lessons.

Glad you figured this out. `.Data` is a for list pages (i.e., nodes) that represents the data (pages, or the list of pages) available to them. The one caveat is that the homepage can use `.Data.Pages` for _all_ pages across the site. A single page doesn’t have `.Data.Pages` because a single page, by default, doesn’t have any pages underneath it.

Hopefully this explanation of Hugo lists helps make things a bit clearer for future reference:

[https://hugodocs.info/templates/lists/](https://hugodocs.info/templates/lists/)

Also keep in mind that from within a section page, you can use the even short `{{range .Pages}}`…

HTH…

---

<div class="post-metadata">

**Author:** ![onur](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/onur/32/2953_2.png) [@onur](https://discourse.gohugo.io/u/onur)\
**Post date:** [April 8, 2017, 9:13pm UTC](https://discourse.gohugo.io/t/range-through-content-type-from-single-template/6081/4 "2017-04-08T21:13:28Z")

</div>

Thanks @rdwatters, definitely helps!

---

<div class="post-metadata">

**Author:** ![bep](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/bep/32/3332_2.png) [@bep](https://discourse.gohugo.io/u/bep)\
**Post date:** [April 8, 2017, 9:34pm UTC](https://discourse.gohugo.io/t/range-through-content-type-from-single-template/6081/5 "2017-04-08T21:34:34Z")

</div>

Also, when doing where ranges in the single template, I would look into using the `partialCached` func, for performance reasons.

---

<div class="post-metadata">

**Author:** ![rdwatters](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/rdwatters/32/2848_2.png) [@rdwatters](https://discourse.gohugo.io/u/rdwatters)\
**Post date:** [April 8, 2017, 9:44pm UTC](https://discourse.gohugo.io/t/range-through-content-type-from-single-template/6081/6 "2017-04-08T21:44:49Z")

</div>

Ooo. Good point. For reference, @onur

[https://hugodocs.info/functions/partialcached/](https://hugodocs.info/functions/partialcached/)

---

<div class="post-metadata">

**Author:** ![STQOE](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/stqoe/32/3292_2.png) [@STQOE](https://discourse.gohugo.io/u/STQOE)\
**Post date:** [June 15, 2017, 7:53am UTC](https://discourse.gohugo.io/t/range-through-content-type-from-single-template/6081/7 "2017-06-15T07:53:24Z")

</div>

For reference sake @bep does “for performance reasons” relate to Hugo’s compile time?

---

<div class="post-metadata">

**Author:** ![bep](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/bep/32/3332_2.png) [@bep](https://discourse.gohugo.io/u/bep)\
**Post date:** [June 15, 2017, 8:46am UTC](https://discourse.gohugo.io/t/range-through-content-type-from-single-template/6081/8 "2017-06-15T08:46:14Z")

</div>

> [@STQOE](#):
>
> For reference sake @bep does “for performance reasons” relate to Hugo’s compile time?

I call it “build time” … or time to build a site, whatever. But yes, it is directly related to that.

---

<div class="post-metadata">

**Author:** ![STQOE](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/stqoe/32/3292_2.png) [@STQOE](https://discourse.gohugo.io/u/STQOE)\
**Post date:** [June 15, 2017, 12:36pm UTC](https://discourse.gohugo.io/t/range-through-content-type-from-single-template/6081/9 "2017-06-15T12:36:50Z")

</div>

Thank you. Always…

---

<div class="post-metadata">

**Author:** ![STQOE](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/stqoe/32/3292_2.png) [@STQOE](https://discourse.gohugo.io/u/STQOE)\
**Post date:** [June 15, 2017, 12:38pm UTC](https://discourse.gohugo.io/t/range-through-content-type-from-single-template/6081/10 "2017-06-15T12:38:14Z")

</div>

Or, more appropriately, #ThankHu.
