Slice different variables to one

Good morning,

I have the following structure

  • /data/product category01/product1.yaml
  • /data/product category01/product2.yaml
  • /data/product category01/product3.yaml
  • /data/product category02/product1.yaml

here are the data stored that do not change per language.

my /content folder structure looks like this:

  • /content/product_category/product1/index.en.md / index.de.md / index.fr.md

and so on.

here are the data that change per language

Now I have my product.html file and I want to access the data from .md and .yaml files depending on which product is called.

I thought I could solve this in an intelligent way :slight_smile:

  {{ define "main" }}

  <div class="product">
  {{$titlename := .Page.Title}}
  {{$range := "$.Site.Data.product."}}
  {{$info := ".Info"}}
  {{$group := slice $range $titlename $info}}
  
  {{range $group }}
  
  {{.Name}}
  
  {{end}}
</div>

{{ end }}

But that doesn’t work.

What am I doing wrong? And is there possibly a much better way to build the structure?

You are range-ing over $group, which in this case is an array of strings:

$group = [ "$.Site.Data.product." , .Page.Title , ".Info" ]

Have a look at the index function.

Please note that it is easier to help if you have your site code somewhere we can have a look at instead of trying to recreate it ourselves. Have a read about Requesting Help

2 Likes

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