Hi!
I am trying to implement logic in my layout that generates buttons with anchor links and shows respective content piece from front matter when respective button (tab) is selected.
For example, this my front matter:
title: "Test"
draft: false
type: "system"
layout: single.html
content:
- test1:
title: "Test1"
description: "Lorem ipsum"
- test2:
title: "Test2"
description: "Lorem ipsum"
- test3:
title: "Test3"
description: "Lorem ipsum"
Here’s the layout:
I implemented the page header that iterates over content
in front matter and generates buttons for “test1”, “test2”, “test3” along with anchors in URL.
{{/* PAGE HEADER */}}
<section class = "p-6">
<h1 class="text-4xl font-extrabold">
{{ .Title | emojify }}
</h1>
<div class = "flex flex-row items-start pt-6">
{{ range $index, $element := .Params.content }}
{{ range $key, $value := $element }}
<a class="px-4 py-1.5 flex-row items-center align-middle rounded-full text-base text-darkGreen bg-lime-100" href="#{{ $key }}">
{{ $key }}
</a>
{{ end }}
{{ end }}
</div>
<hr class="mt-6 border-footerGray">
</section>
Now, I am struggling to understand how I can display either “test1”, “test2” or “test3” content when the button is selected.
{{/* CONTENT BLOCKS */}}
{{ with .Params.test1 }}
<section class = "mt-6">
<div class = "flex flex-row items-center justify-end">
<div class = "p-6">
<h2 class="mt-6 text-5xl font-bold">
{{ .title | markdownify }}
</h2>
<p class = "mt-6 pb-6 text-lg">
{{ .description | markdownify }}
</p>
</div>
</div>
</section>
{{ end }}
Image referenceL
Any help is appreciated, I am trying to achieve this using only Hugo functionality, if that’s possible.
Thanks!