Linking pages in a template and showing their content

Hello everyone, I am currently trying to implement a site in Hugo which would allow to browse 3D models submitted by FreeCAD contributors.
The site will by used in conjuction with a FreeCAD Workbench to easely import the models, as for now the only option is to download models one by one or the entire library.
I am currently trying to create the base structure of the site and I am having difficulties with the linking of some pages.

To make maintaining the site easier, I used the DRY process and set up the navbar in a template :

<nav class="navbar navbar-expand-lg bg-body-tertiary">
    <div class="container-fluid">


      <button class="btn btn-dark" type="button" data-bs-toggle="offcanvas" data-bs-target="#offcanvasScrolling" aria-controls="offcanvasScrolling"><i class="bi bi-list"></i></button>


      <a class="navbar-brand" href="{{.Site.BaseURL}}">
        {{ with resources.Get "images/navbar/FreeCAD-wordmark-dark.svg" }}
          <img class="navbar-img" src="{{.RelPermalink}}" width="140" height="40" alt=""></a>
        {{ end }}
      </a>
      
      <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
        <span class="navbar-toggler-icon"></span>
      </button>
      <div class="collapse navbar-collapse" id="navbarSupportedContent">
        <ul class="navbar-nav me-auto mb-2 mb-lg-0">
          <li class="nav-item">
            <a class="nav-link" href=""></a>
          </li>
          <li class="nav-item dropdown">
            <a class="nav-link dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown" aria-expanded="false">
              Dropdown
            </a>
            <ul class="dropdown-menu">
              <li><a class="dropdown-item" href="#">Action</a></li>
              <li><a class="dropdown-item" href="#">Another action</a></li>
              <li><hr class="dropdown-divider"></li>
              <li><a class="dropdown-item" href="#">Something else here</a></li>
            </ul>
          </li>
          <li class="nav-item">
            {{$about:= .Site.GetPage "about" }}
            <a class="nav-link" href="{{ $about.RelPermalink }}">About</a>
          </li>
        </ul>
        
      </div>
    </div>
  </nav>

The 1st part that bugs me is the linking of the about page.
The principle is the following:

  • Create a template called about.html
  • Apply this template to a about.md file to make writing the content easier.
  • link the produced html file in the sidebar.

First the linking. I tried to use the GetPage method, but when I add <p>test</pd in the about page, I don’t see the paragraph in the page. What would be the best in this case?

Second, displaying the content of the file. I tried to add the Content Method like so:

  {{ with resources.Get "content/about.md" }}
    {{ .Content }} 
  {{ end }}

but it didn’t work. What would be the best to set the template to render the content of the .md file?

Thx in advance

There is almost never a good reason to use this method. Use site.Home.RelPermalink instead.

Where, specifically, are you placing this text? In the about.md file or the about.html template?

Hi, thanks for the response, I just swapped the old method for the new one and it still works.
As for the text, it is placed in the template.

If you placed <p>test</p> in the template then it’s not part of the content.

Yes I know, but when I go to localhost:ABCD/about I don’t get this text on my screen. This is related to my 1st issue.

Content printing in the page is the 2nd issue.

I think you’d better share your project repository.

But I shared it, it’s right here :

EDIT: Looking back, yeah that’s not obvious at first sight, sorry.

content/
├── _index.md
├── _index.md.toml
├── about.md
└── about.md.toml

???

You cannot separate meta data from the content file.

oh sorry, I thought I saw that in a hugo article

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