I feel like there should be an easy way to do this, but I can’t find it. I need specifically chose a child from a collection while looping through the collection. The order doesn’t really matter, just as long as I can pick say the nth child in the collection wherever I need it and place it where I want to. I guess I don’t even need to loop through the collection. I just need to select each child specifically. I’m aware of
loop.first and loop.last
---
but what about children in-between the first and last?
I have a page that needs to show each child in a portfolio of items, but each item is not formatted the same way. The general layout is
<a href="/path/to/first/item/"
<a href="/path/to/second/item/"
<a href="/path/to/third/item/"
```
And so on. I can't just iterate over the entire collection because I need the first child to be in "style1", the second child in "style2" and so on. I tried
```
{% for child in collection %}
{% if loop.first %}
<a href="{{ child.url }}"
{% endif %}
<a href="/path/to/second/item/"
<a href="/path/to/third/item/"
{% endfor %}
```
which works for the first child, but no others. I tried other things like
```
{% set first_child = collection[1:1] %} and {% set first_child = collection|slice(0,1) %}
```
to no avail. Any thoughts?
Your solution seems like the best way to me, although I think something like this might work if your class name is actually style 1, style 2, style 3 etc.:
I didn’t add it before because it would confuse and bloat things. But the layout looks sweet. It’s a website I made earlier in the year that I’m porting to grav. But it makes this process a bit tedious.
Your first solution is better for me because I can specify the exact spot where I want each item to go straight in the header. I’m going to try and implement this
If you wrap the whole collection in a parent div, you can change the position of a child element with css by changing a class on the parent. You can then just class="wrapper highlight{{ num-to-highlight }}" in your template and you can change it client side too with a little javascript.
The position absolute pulls that item out of the DOM flow so the items after it should just slide up.