Forum
Repeating region show text left, img right then img left, text right
I have a region that can be repeated that has text taking up 50% of the container width and an image taking up the other 50%.
For the first item the text is to be on the left and the image on the right, then for the next item the image will be on the left and text on the right.
I did try using <perch:every nth-child="odd"> and <perch:every nth-child="even"> but this doesn't seem to work where it is the region (as opposed to a repeater) that is repeated.
Can I do this with perch? If so how?
Hi John
Wouldn't you just use CSS for this? Perch doesn't really care about layout.
Personally I would use flexbox to reverse the order of the image and text inside the div by using :nth-child(even) to target the 2nd, 4th etc divs and flex-direction: column-reverse to flip the order of the items. But you could use floats and clearfix I guess if that floats your boat ;) !
Hope this helps,
Jon
Are you using a multiple item region?
Jon - Thanks for the reply. Unfortunately I can't do much with the CSS as this was supplied to me (created by designer in webflow), my role in this project is to integrate it with perch (which I am new to!). Hence, looking for a solution where I can branch based on the iteration of a multiple item region. I agree this is less elegant solution and less DRY than doing it with CSS. I would typically use bootstrap, if it were a project I'd created, which makes this easy.
Drew, yes - using a multiple item region, screenshot: https://bit.ly/2qWrWHV
Cheers for the help.
The
perch:every
tags will work with a multiple item region.That is what I had done but it wasn't working. I re-saved the 'region options' page which seemed to refresh it and it started to work (almost) as intended. Is that something you commonly need to do with perch?
I now have a separate issue - no fields are showing within the nested blocks. Here's the code:
This shows in perch admin like this (screenshot) : https://bit.ly/2qWML5U
Am I doing something wrong?
Hi John,
You can only have one set of <perch:blocks></perch:blocks> tags in a template all of your <perch:block></perch:block> tags would have to go in there.
Thanks Dexter. I have re-worked the template now to not include <perch:blocks>. Which is a little annoying but I can live with it.
Thanks,
John