Render index.md as single


#1

Hello,
I’m new to hugo
i try to use i as an cms and not as an blog engine.
everything works fine, but i want to have an index.md
that renders “/” as single page and not as list of posts

i’m using https://github.com/spf13/hyde

this must be simple, but i find nothing about it

btw the
hugo new --kind “$randomstring” seems to does nothing, is this a bug?


Site is only built correctly when being live-reloaded
#2

/ is a list template.

With the current version of Hugo, everything is a page. So, you can do this with your source organization:

.
    content/
        _index.md

Note Use _index.md and not index.md. This will be the content and front matter for your homepage now. Once you have content added to this page, you can call it in the layouts/index.html template the same way you would any other individual content file via {{.Content}}. If you have errors with this approach, I would recommend filing an issue on the theme’s github repository. It looks like it hasn’t been updated in a while…since it requires only v14 of the HUGO to run.

HTH


#3

The easiest thing to try is:

Remove this section from the Homepage template

              {{ range .Data.Pages }}
          <div class="post">
            <h1 class="post-title">
              <a href="{{ .Permalink }}">
                {{ .Title }}
              </a>
            </h1>
        
            <span class="post-date">{{ .Date.Format "Mon, Jan 2, 2006" }}</span>
        
            {{ .Content }}
          </div>
          {{ end }}

Then create an _index.md file in the /content/ folder: /content/_index.md with your content.

Put

  <div class="post">
    {{ .Content }}
  </div>

instead of the removed part of the template and everything should be fine.


#4

_index.md
does not work, can you give me a full example please?

i dont want to touch anything in themes/
(cant be right, hugo should be a cms, not blog only)

there are 2 templates in “hyde”:

ls -1 themes/hyde/layouts/_default/
list.html
single.html

is there no way to force the use of “single” via header?

hugo new --kind doing nothing is a bug?
i cant find “_$page.md” in the docs

is there a chat group?
i’m willing to help and improve the docs as well


#5

The home page has a separate template, index.html in the theme folder.
single.html and list.html are used for rendering the content of the subfolders of your content directory.

The way index.html is set up in this theme is to give a list of posts ({{ range .Data.Pages }}) so it does not read your _index.md at all as it looks through all your other content pages and puts this in the homepage.

So I would try to change the index.html template file (/themes/hyde/layouts/index.html) to:

{{ partial "head.html" . }}
<body class="{{ .Site.Params.themeColor }} {{if .Site.Params.layoutReverse}}layout-reverse{{end}}">

{{ partial "sidebar.html" . }}

    <div class="content container">
<div class="posts">

  <div class="post">
    <h1 class="post-title">
        {{ .Title }}
   </h1>

    {{ .Content }}
  </div>
  {{ end }}
</div>
</div>

  </body>
</html>

and this should show up the Title and Content of your Frontmatter in /content/_index.md


#6

thanks,
so this is just the wrong theme for what i want to do
and there is no workaround without touching anything inside the theme folder

i’ll read more docs&source
i’m not happy with this :slightly_smiling:


#7

Yes, supplied themes are just for “standard use”.
I started to use Hugo for a “blog section” of my home page, but recently I set up a theme for the complete website with a set of “normal pages” as well as a blog section on top.
So as I read through the docs and this forum and get things working slowly I try to write a german language tutorial in the blog section. Maybe this may help others - but it helps me structuring the information and understand hugo … :slightly_smiling:


#8

The first comment is semi-correct and the second comment is incorrect.

To piggyback on what @ominty just said, you should create your own index.html file, but do it in your root project directly and not in the theme directory. The lookup order will privilege your index.html template over the theme’s index.html template. This is by design and for very good reason: you are able to override the theme templating while still keeping compatibility with the upstream of the theme.

So, instead of making the recommended layout at /themes/hyde/layouts/index.html, just make it at /layouts/index.html.

If you are not finding that you can access {{.Content}} while running hugo, the first thing is to make sure you are running the latest version via hugo version.

HTH.


#9

Thank you!

vim content/_index.md
and
cp themes/hyde/layouts/_default/single.html layouts/index.html
works

any way to include that and not copy it, or not use a symlink?

Thank you!


#10

[quote=“rdwatters, post:8, topic:5533”]
you should create your own index.html file, but do it in your root project directly and not in the theme directory. The lookup order will privilege your index.html template over the theme’s index.html template.
[/quote]explicit consent
… and sorry for not thinking about that. That’s because I try to set up my own theme from scratch and so I’m working in the /themes directory all the time …


#11

Ah! Thank you so much @ominty . I am new to Hugo as well and I was having the exact same problem with the theme hyde-hyde (which is derived from hyde).

I spent hours and hours searching until I found your post :slight_smile:.

This worked beautifully.

Note: as pointed out by @rdwatters, I did not edit the theme, but created my copy (following advice I had found here before finding this forum).