[SOLVED] Extra page with information from all content md files (metadata)

Hi all

I have a feeling this is an almost trivial question…

I want to create a page like the layouts/index.html, which in my case uses a partial for each project content file (the theme is ~HugoMDL). I don’t want to change the main front page, but I want to create a page that checks/shows the completeness of the metadata for each project I have.

To test it, I modified the layouts/index.html and it works like I want to, but how do I get this page next to the normal front-page index.html as a separate page called “index2.html” or “completeness.html” and then somehow link to that from some about page or whatever?


Simon, webmaster of Eduweb homepage

What you could do is copy your desired template layout to a new file and put it in a place like /layouts/meta/single.html
See here: https://gohugo.io/templates/single-page-templates/

Then, make a file called index2.md in /content/

in the front matter of that page, put:

type = "meta"
layout = "single"

Something like that might work.

tnx, I’ll give it a try tomorrow…


A page is generated, but I don’t see the metadata for all the project pages. Do I need some sort of other “Path” to the page variables to get the frontmatter data from the project files?

In the single.html I have this to loop over the project files and print a table row for each project with all the relevant metadata

{{ range first $.Site.Params.frontpageposts .Data.Pages }}  
  {{ if eq .Type "project" }}{{ .Render "project-card-status" }} {{ end }}  
{{ end }}

The project1 files reside in content/project/project1.md

$.Site.Params calls Parameters set in config.toml See: https://gohugo.io/variables/site/#the-site-params-variable

How are you setting the frontpageposts parameter?

Also your range function is not correct.

To help you construct it I need to ask how have you arranged your content?
Are all the pages you want to render under the section /projects/?
Do you want to render all of them or only the ones with the above parameter?

in the config.toml
I have this line:

frontpageposts = 40 #number of post cards to display on frontpage +1

(it’s 40 to make sure all are listed, as there are much less than 40 projects)

I guess the original range worked, because it was the toplevel index.html with access to the .Data.Pages “array” of all pages. Can I access this same array from the new single.html?

Sure you can. See the .GetPage function.

OK, so how do I get from .GetPage to all the pages?


{{ range $.Site.GetPage "page" "project" }}  
  <!-- tables lines for each project -->
  {{ .Render "project-card-status" }}  
{{ end }}

doesn’t work…

I want to range over all the project/*md files and render the layouts/project/project-card-status.html template for each project.

Basically what I did in the first post, but that was only working when it was the toplevel index.html…

I feel like I’m lacking some kind of basic understanding or assumption about Hugo :confounded: :cry:

Try {{ with .Site.GetPage "section" "project" }}

Read the Docs more carefully.
.Site.GetPage "section" is for all posts in a section
.Site.GetPage "page" is for an individual page.

As I understand it, range can loop over a bunch of things, with generates a single instance to work with…

So I guess I need something with range…

When I try your suggestion I get:

WARN 2017/08/04 12:46:46 .Render only available for regular pages, not for of kind "section". You probably meant .Site.RegularPages and not.Site.Pages.

among the messages from hugo.
When I try range it gets worse.

The docs aren’t very clear to me about what comes out of .GetPage, except common sense says: it’s a single object, otherwise it would have said: .GetPages, which is not a known function (yet? :wink: )

No. .GetPage gets both regular pages and list pages. Everything is a Page in Hugo these days.
Also forget about range when using .GetPage it’s a different function.

Now regarding the .Render error what is inside this template? Where is it located?
You should be able to get all the posts from your projects section on a regular page and render them as you please using another way.

Since you said that you got this working earlier in your index.html under /layouts/ create the following template /layouts/sections/projects/index.html copy the contents of your /layouts/_default/list.html and then modify it with the code you got working earlier. Your projects will then be available on your section’s list page i.e /projects/

OK, I’ll go try that now. Meanwhile, here’s a git repo with all the code (and some quite big files, which are just static content)

(look in the branch “completeness”)

And if you want to “run” it, you need https://gitlab.science.ru.nl/cncz/eduweb-theme.git and put it in themes/HugoMDL

Simply changing /layouts/completeness/single.html to:

{{ with .Site.GetPage "section" "project" }}
{{ .Render "project-card-status" }}
{{ end }}

Made the Hugo Server error go away. Also I am not getting the .Render error you mentioned above.

But I am not sure about the location of the rendered page for this template. e.g. http://localhost:1313/completeness/ gives me a 404.

the page is at http://localhost:1313/meta/

The resulting table is empty

I’ve updated the completeness branch

under the “normal” bit on the default index.html (http://localhost:1313/) is the table I want to see on a separate page (for obvious reasons :wink:

Of course it’s empty there is no project-card-status.html in your repo.

There is only a project-card.html under /themes/HugoMDL/layouts/project/project-card.html

that’s weird, I don’t see it in a clean clone either… git add looks like it already has it…

Well then push it to your completeness branch. Lol!

I don’t understand why the clone doesn’t show it…

Of course:
git checkout completeness after clone…