How to use one layout for different partials

Hi. I will try to explain it as best as i can.

In my content folder there are few files: investment1.html, investment2.html, investment3.html etc.

i have a layout in _default named “investments” that looks like this:

{{ define "main" }}

	{{ partial "spotlight" site.Data.XXXX }}

	{{ partial "template/footer" . }}

{{ end }}

I want to use same layout file, but different yml files in data folder. for example if content file is named investment1.html with title “investment1” i want it to use investment1.yml in Data

So i think i need to find a way to change {{ partial "spotlight" site.Data.XXXX }} to the content file title

Im so bad at this, sorry.

You need to use the index function.

directory structure

content/
├── investments/
│   ├── investment-1.md
│   └── investment-2.md
└── _index.md
data/
└── investments/
    ├── investment-1.yaml
    └── investment-2.yaml

layouts/investments/single.html

{{ with index site.Data.investments .File.ContentBaseName }}
  {{ .name }}
{{ end }}
2 Likes

Thanks a lot! I was able to make it generate sites. My single.html layout looks like that now:

{{ define "main" }}
    {{ $spotlightData := index site.Data.investments .File.ContentBaseName }}
    {{ with $spotlightData }}
        {{ partial "spotlight" . }}
    {{ end }}

{{ partial "template/footer" . }}

{{ end }}

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