How to use site config file to determine which pages on site front page?

Hi, I want to list some pages on my front page and change it regularly. I think it would be easier if I can just make a list at the config.toml file and change it there to pick the right page whenever I needs to.

Here are my content structure:

└── content
└── about
| └── index.md
├── courses
| ├── 105
| | └── _index.md
| | └── 1.md
| ├── 110
| | └── _index.md
| | └── 1.md
└── 208

At my config.toml file, I add a [params.course] variables and list pages I want to show on front:

[params.course]

front = ["105","110","205"]

And in the front page template, I have:

{{ range (.GetPage "/courses").Pages "in" site.Params.course.front }}

{{ end }}

And I got error : at <"/courses">: wrong number of args for Pages: want 0 got 2"

Can anyone tell me how to get this right? Or any other better way to get this done? I know the Page.Params can do it but I don’t want to change the individule page frontmatter everytime. Thank you in advance!

Try something like this

{{ $courses := (.Site.GetPage "/courses").Pages }}
{{ range $courses }}
  {{ $shouldShow := in $.Site.Params.course.front .File.BaseFileName }}
  {{ if $shouldShow }}
    <!-- Render your pages here ... -->
  {{ end }}
{{ end }}
1 Like

Thank you so much @zwbetz! It works very well!

Just one more follow up question, if I want to use $.Site.Params.course.front to match section/folder instead of markdown file, how would I do it? right now, I am using .Title instead of File.BaseFileName like this:

{{ $shouldShow := in $.Site.Params.course.front .Title }}

Because my content structure is like:

content/en/courses/105/_index.md 1.md 2.md
content/cn/courses/105/_index.md 1.md 2.md

the .Title only show the title from _index.md front matter filed but not the actual sub section/folder name, like 105. then I had to set both languages of the title for the $.Site.Params.course.front I am wondering is there are something like .Title but for the actual section/folder name? would be great to fix my problem.

Thank you and Merry Christmas!!

Glad to hear it’s (partially) working.

Am not sure about that one. You could play around with .File.Dir too.

Or you could try filtering the pages down with a where clause first.