GroupByParam with default parameter value

I have some pages under a section. For example, there are five pages under tech section:


I have already got a sidebar to show those pages, and I want them look like this:


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 }}
    {{ 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"?

Well for starters, can we see your code? Afterwards we might be able to help you better!

I think that you can not group by parameter if this parameter is not specified in the file. You can only exclude pages without a parameter from the list.

Thank you and I have update my problem description with my code.
When I replace this group with title and slug, there is no error.

Yes, but could we set a default value for those pages which doesn’t have this parameter. I know there is a default function but it seems there is no way to integrate them.

A post was split to a new topic: Grouping pages by parameter when parameter is not set