Hugo

Show latest game test & latest news on landing page EDIT: repo added

Hello,

I want to show latest game test and latest news on the landing page.
What I have:
content/games/gta5.md
content/news/news1.md

For that I created:
mytheme/partials/latest-item.html
with a dummy text for testing.

I could display the dumme text with {{- partial "latest-item.html" . -}} in
mytheme/layouts/index.html

I can display all news or all games here:
mytheme/layouts/_default/list.html
from:
mytheme/layouts/games/single.html

{{ .Type | humanize }}
  {{ .Content}}
  {{ range .Pages }}
  {{ .Title}} //name of game/news
  {{ .Date.Format "2 Jan 2006" }}
{{ .Params.text}}
{{ end }}
{{ end }}

It’s been few days ago, I am not even sure why it is working.
If I put the lines above into latest-items.html it don’t work.

How can I, get the articles/access value from content/games/gta5.md & content/news/news1.md
on index.html?
I think I need two html for that, one for game and one for news. latest-game-test.html latest-news.html
but how to access relevant data from content?

Here a screenshot of my text editor and the directory structure and the working list.html (overview of all games/news)

Thank you for your time.
EDIT:
Created a img to show what I want, because I have some troubles in describing it in English.

Please share a code repo for your project. If you can’t share that one, please make a sample repo to share. :slight_smile:

Hi,
here is the repo:

See the answer I gave to a very similar question.

Sorry, I am a slow learner, do you have time t go through your answer real quick?

He wants a widget with favorite links, I want a widget with latest two articles from category games and news.
Q1) We both need a .md file for our widgets? I could create:

content/newst-article/ _index.md newst-article.md newst-game.md

newstNews: “title news”
link: “???”


newstGame: “game test title”
link: “???”

If it works that way:
Q1.2) How would the link look like? If I open server and navigate on it the url looks like this
http://localhost:1313/games/gta5/
The directory of the file is:
content/games/gta5.md
mytheme/layouts/games/single.html

Big difference is: I need the article with the latest date.
My games and news article have a date:
date: 2018-10-19T16:10:36-04:00

Q2) How to code something like this:

  • Take md file from this dir: e.g. content/games with the latest date
  • Put the info from the md file into a template
  • Render in on index.html
    To have a preview I need to create a widget, right? It would have a img, title and a link to it and it would read from:
    content/newst-article/ newst-article.md newst-game.md So it knows which article is the latest. It would be a manual labor to do it every time, but it would okay for me.

I am totally lost :S I messed up this thread…

Two different between you and the person in the post I linked to:

  1. That person needed to create the post he wanted to list, you already have them.
  2. That person wanted to list posts in the sidebar, you want to list them on the front page.

So you have no need to create any special posts as you seem to suggest in Q1. You already have the games and news articles set up. The other question you have I do not understand.

{{ .Params.img }}
{{ .Params.cover }}{{ .Params.title }}>
{{ .Params.excerpt }}
{{ .Content }}
{{ end }} //deleted all HTML

Thank you frjo for helping me out. Above is my code for a article/game test about the game Skyrim, the URL is http://localhost:1313/games/skyrim/.
This HTML file is made for all games. If I put this code on index it don’T work.
What do I need to do, so the code can be used in index and all the variables (.params.title, date, name) are taken from the content/games directory?

You need to nest that code within a range (If you haven’t done that already). Then you can order pages by date in reverse, so that newest pages show first.