How do I have a custom index page while using the previous index page aswell?

Hello! Total newbie to hugo here!

I’m using this theme CaiJimmy/hugo-theme-stack: Card-style Hugo theme designed for bloggers (github.com) in my hugo site. I understand that layouts/index.html is where the landing page of the site lives. I want to have my own custom index.html as a replacement to that file, so I replace it. But I also want that previous index.html from the theme. Therefore, I create a file called projects.html in layouts/ and paste the code in. Then I create a file called content/projects.md with the frontmatter layout: projects but that does not display anything, and probably falls back to layouts/_default/single.html How do I use this code to display projects.html(the index.html from the theme)?

{{ define "main" }}
    {{ $pages := where .Site.RegularPages "Type" "in" .Site.Params.mainSections }}



    {{ $notHidden := where .Site.RegularPages "Params.hidden" "!=" true }}
    {{ $filtered := ($pages | intersect $notHidden) }}
    {{ $pag := .Paginate ($filtered) }}

    <section class="article-list">
    
        {{ range $index, $element := $pag.Pages }}
            {{ partial "article-list/default" . }}
        {{ end }}

    </section>

    {{- partial "pagination.html" . -}}
    {{- partial "footer/footer" . -}}
{{ end }}

{{ define "right-sidebar" }}
    {{ partial "sidebar/right.html" (dict "Context" . "Scope" "homepage") }}
{{ end }}

I also tried putting this under layouts/_default/projects.html and use them there but then I would get this error

ERROR Rebuild failed: render: failed to render pages: render of "page" failed: layouts\_default\projects.html:11:41": execute of template failed at <$pag.Pages>: error calling Pages: runtime error: invalid memory address or nil pointer dereference

What can I do here?
Thanks for any support in advance!

1) Create the template: layouts/_default/projects.html

2) Create the content: content/projects/_index.md (must be a section page)

3) Add front matter to the content:

layout = 'projects'
1 Like

That works! thanks a lot

1 Like

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