How to range a specific data files (relative to page)

I have placed yml files directly in my data directory.

I have named them relative to the pages where I want to use them.

I am able to use the following to bring up data from a single file:

{{ $hoteldata := $.Site.Data.york__yorkshire_archery.hotels }}

<ul>
{{ range first 6 $hoteldata }}
   <li>{{ . }}</li>
{{ end }}
</ul>

However, this will show the same data on all of my pages.

I would like to do something like this:

{{ $hoteldata := $.Site.Data.$city__$venue.hotels }}

I realise this doesn’t work.

Could anyone point me in the right direction please?

Use the index function.

Thank you. That did the trick.

The solution was:

{{ $hoteldata := (index .Site.Data $datafile).hotels }}

<ul>
{{ range first 6 $hoteldata }}
   <li>{{ . }}</li>
{{ end }}
</ul>

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