Can page resources be put into a custom order?

Hello,

I wonder, if it possible to put the page resources put into a custom order? I’d need such a feature for a gallery, to create a custom order.

What I can imagine, would be something like:

resources:
- src: "*/images/a.jpg"
  params:
  - weight: 10
- src: "*/images/b.jpg"
  params:
  - weight: 30
- src: "*/images/c.jpg"
  params:
  - weight: 20

This would result in the following order: a - c - b

Thanks in advance
Chris

Does the solution at Trying to order a list of page resources work?

I’ve tried the following, but without success:

{{ range sort ($.Page.Resources.Match (.Get 0)) ".Params.weight" }}
  RES={{ . }}<br/>
{{ end }}

The result was:

RES=Resource(image: images/a.jpg)
RES=Resource(image: images/b.jpg)
RES=Resource(image: images/c.jpg)

There are two possible ways to solve this:

  1. Someone comes by and can eyeball your issue, or
  2. Follow the advice at Requesting Help and share your project’s code

Good luck! :slight_smile:

My code, which is in a very early stage, can be seen at https://gitlab.com/clorenz/lenzula.git

The page in question can locally be seen at “/buecher/bluehende-quilts/”, where the output shows, that the resources are in the wrong order, not in the order, I wrote in the contents’ markdown.

params should be a map, not a list:

resources:
- src: "*/images/a.jpg" 
  params: 
    weight: 10 
...
1 Like

Thank you, you are right, it should be a map, but that also does not help.

It must be something trivial, which I’m missing here, since I generally cannot access any resource params at all.

resources:
- src: "*/images/peek3.jpg"
  params:
    weight: 20
    title: "Foobar"
- src: "*/images/peek1.jpg"
  params:
    weight: 10
- src: "*/images/peek2.jpg"
  params:
    weight: 30 

Am I using a wrong syntax here? I’m using the latest Hugo 0.45

Can you try:

resources:
  - src: "images/peek3.jpg" ## without the preceding '*/'
    params:
      weight: 20
...
{{ range sort ($.Page.Resources.Match (.Get 0)) ".Params.weight" }}
  RES={{ . }} \ {{.Params.weight}}<br/>
{{ end }} 

Should result in:

RES=Resource(image: images/peek1.jpg) \ 10
RES=Resource(image: images/peek3.jpg) \ 20
RES=Resource(image: images/peek2.jpg) \ 30

*haven’t tested on 0.45 yet though, still on 0.44

I’m sorry, but with 0.45, I still don’t get the order and I also don’t see the “weight” values in the output.

My frontmatter contains:

resources:
- src: "images/peek3.jpg" ## without the preceding '*/'
  params:
    weight: 20
- src: "images/peek1.jpg"
  params:
    weight: 10
- src: "images/peek2.jpg"
  params:
    weight: 30

My shortcode contains:

Retrieving {{ (.Get 0) }}<br/>
{{ range sort ($.Page.Resources.Match (.Get 0)) ".Params.weight" }}
  RES={{ . }} \ {{.Params.weight}}<br/>
{{ end }} 

And the output is:

Retrieving images/peek*.jpg
RES=Resource(image: images/peek1.jpg) \
RES=Resource(image: images/peek2.jpg) \
RES=Resource(image: images/peek3.jpg) \ 

Is there anything basic, I’m missing here? Maybe a misconfiguration?

Remove line 31 from the front matter of the file under /home/alex/Downloads/lenzula-master/content/books/blooming-quilts/index.de.md

YAML takes only 1 resources: parameter you have it twice.

By removing this you will get your .Resources sorted by Weight.

RES=Resource(image: images/peek1.jpg) \ 10
RES=Resource(image: images/peek3.jpg) \ 20
RES=Resource(image: images/peek2.jpg) \ 30
2 Likes

Great! It finally works! Such a trivial but nasty error…

Thank you very much for your help!