I have some pages under a section. For example, there are five pages under tech
section:
\tech
\python.md
\vim.md
\javascript.md
\hugo.md
\git.md
I have already got a sidebar to show those pages, and I want them look like this:
Tech
Python
JavaScript
Vim
Git
Hugo
Because I think both python and javascript are language, so if I give a group
in front-matter of these two pages, they will get on the list together.
My code:
{{ range .Data.Pages.GroupByParam "group" }}
{{ range .Pages }}
<li class="{{ if eq .Permalink $link }}active{{ end }}" >
<a href="{{ .Permalink }}">
{{ .Title }}
</a>
</li>
{{ end }}
{{ end }}
It seems getting error while I do this right now because some pages don’t have this group
property in the front matter:
ERROR 2018/03/29 11:20:05 Error while rendering “section” in “”: template: /Users/hugh/Documents/code/project/2017-blog/memoex/themes/blue/layouts/_default/list.html:5:15: executing “main” at <partial "note-sideba…>: error calling partial: template: theme/partials/note-sidebar.html:28:30: executing “section-tree” at <.Data.Pages.GroupByP…>: error calling GroupByParam: There is no such a param
Right now, I could use weight
in front matter to achieve this kind of sorting, but weight
only works with numbers and numbers is hard to remember.
So is there some way to set default value to group
for all pages that doesn’t have this group
property in front matter before I do this range .Data.Pages.GroupByParam "group"
?