-
-
Notifications
You must be signed in to change notification settings - Fork 7.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sort template func fails for Pages #1330
Comments
OK, reading the doc, this isn't supported. "Params.somefield" isn't a field on Page. Sorting by nested map keys could maybe be implemented, but that is not on my todo-list. Can you confirm that constructs like
Work as expected? |
confirm, same result
|
@derekperkins doesn't the sort func support pointers? |
@bep it doesn't dereference pointer value. |
Fixed in my local repository but I reconsider it's really enough to solve this |
@bep I would have thought so, but I guess not. :) I haven't touched Hugo in 7-8 months, so I don't really remember. Should be easy enough to add an @tatsushid Go ahead and submit your PR with the fix. |
'sort' template function used to accept only each element's struct field name, method name and map key name as its second argument. This extends it to accept a field/method/key chaining key string like 'Params.foo.bar' as the argument. It evaluates sub elements of each array or map elements and sorts by them. Typical use case would be sorting pages by user defined front matter value. For example, sorting pages by 'Params.foo.bar' is possible by writing the following template code {{ range sort .Data.Pages "Params.foo.bar" }} {{ .Content }} {{ end }} It ignores all leading and trailing dots so "Params.foo.bar" can be written in ".Params.foo.bar" This also fixes the issue that 'sort' cannot evaluate a pointer value. Fix gohugoio#1330
I sent a PR. Please see #1334 |
Um trying to make a sort on user defined property as following: in my pages:
and i try to apply sorting as following:
this doesn't fails at compilation, but the list is rendered empty. Am i missing something? |
Well, i was walking in the wrong direction. So, the fix is:
and use weight
this fixed my issue, but there's still a problem using user defined properties for sorting. |
This should be the same:
Sorts by Weigt (and then by date and then by title). |
'sort' template function used to accept only each element's struct field name, method name and map key name as its second argument. This extends it to accept a field/method/key chaining key string like 'Params.foo.bar' as the argument. It evaluates sub elements of each array or map elements and sorts by them. Typical use case would be sorting pages by user defined front matter value. For example, sorting pages by 'Params.foo.bar' is possible by writing the following template code {{ range sort .Data.Pages "Params.foo.bar" }} {{ .Content }} {{ end }} It ignores all leading and trailing dots so "Params.foo.bar" can be written in ".Params.foo.bar" This also fixes the issue that 'sort' cannot evaluate a pointer value. Fix gohugoio#1330
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
sorting list like this:
causing error message:
The text was updated successfully, but these errors were encountered: