Accessing data file from a content file (jekyll user) [solved]

Hi, I am an active jekyll user, checking out hugo.

I use jekyll for my small business - not a blog. I have a few different types of products. I keep info on those products in a data file. With jekyll I can build a product listing page quite easily by adding whatever basic content to a page, and then doing a loop over the product data. Everything is either in that one page or the data file.

Looking at hugo it looks like the product listing page would be a content page, I see hugo supports data files so that should be good, but as far as i can tell I cannot access the data file from the actual content page code - I need to do it from a layout? or a shortcode? is that correct? So within a content page you do not do anything directly with curly brackets? like even to get the page title or other front matter?

You need to create a shortcode for that. You can send parameters to shortcodes so you can do something like this in a content file:

{{< my-products "bananas" >}}

Which is the most stupid example I could come up with this early in the morning (Norway time).

ok, thanks, I am trying to use a shortcode to do this but not having any luck. I can’t tell if a shortcode is not capable of doing what I want, or if it doesn’t like my yaml data file, or if I just can’t get the code correct.

I made a shortcode called core-products.html.
I call it in a content file (happens to be my main index file if that matters) by doing:

{{< core-products >}} - no need to pass in a parameter at this point.

The content of that file:

  {{ range .Site.Data.products }}
          <div class="service-flexitem">
           <a href="{{.url}}">
             <img alt="" src="/assets/img/icons/{{.icon}}" class="img-responsive-hm">
           <div class="service-text">
             <a class="servicea" href="{{.url}}"><h3 class="serviceh2">{{.title}}</h3></a>
         {{ end }}


The content of the products.yaml data file:

- title: Digital Prints
  icon: "digital-prints.jpg" 
  url: "/services/digital-prints/"
  featured: core
  description: "Simple quantity based pricing on Fuji Pro Luster, Glossy and Pearl papers."

- title: Canvas Gallery Wraps
  icon: canvas-gallery-wraps.jpg
  url: /services/canvas-gallery-wraps/
  featured: core
  description: Your image printed on canvas ready to hang on your wall.

All i end up with is testing. It is not even doing something twice - it is just skipping the data items all together.

I have also tried just deleting everything below the range bits and putting {{ . }} and I get nothing still, but if I delete one of the data items and remove the dash and indentation it will then give me all the pieces in one line - but then if I try to get just the title or the url it gives an error I think.

This article shows pretty much the same thing as I am trying to do:

Ah hah - as i was posting that link I looked at that data file and mine one more time and added items: to the top of it and now it works.

Jekyll was perfectly happy without that bit.

I figured I would keep this post since I had already typed it up, maybe it will help someone else.