Creating link from navigation bar to section in the main page (Copper theme)

I’m using Copper theme, and I’d like to make menu navigation liked to sections in the main page.
For example :
When I click on “Benefits” in navigation bar, I want it to take me to section “homepage_tab
in _index.md, which is (B2B Excellence Made Simple) in the screenshot, highlighted in green.

I want to do the same for other ones as well
Channels → to (achivement) in _index.md
Security → to (about_us) in _index.md

my source code can be found github repo

Thank you for the help

Step 1

Add an id attribute to each of the section headings (h2 elements) on the home page.

  1. Override the home page template by copying themes/copper-hugo/layouts/index.html to layouts/index.html.

  2. Replace all instances of this:

    <h2 class="section-title">{{ .title | markdownify }}</h2>
    

    With this:

    <h2 id="{{ .title | anchorize }}" class="section-title">{{ .title | markdownify }}</h2>
    

Step 2

Point the menu entries at the h2 elements by referencing the id attributes you added in the previous step.

[[main]]
name = "Benefits"
url = "#b2b-excellence-made-simple"
weight = 2

[[main]]
name = "Channels"
url = "#available-in-online-and-offline-channels"
weight = 3

[[main]]
name = "Security"
url = "#malas-robust-security"
weight = 4

You have to view the page source to see the value of the id attribute.

1 Like

thank you @jmooring for the help. Much appreciate it.

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