Forum
Pulling first block of specific type from template
I've created a testimonials page with Perch Blocks, so the user can create testimonials that include images, quotes and text blocks. I've got an excerpt of these testimonials being pulled on to the homepage as well as various other pages.
The problem is when trying to pull in an excerpt that has multiple text blocks – this breaks the layout.
Is there a way of only pulling in the first of any type of block? I.e. the first text block, or the first image and ignoring the rest?
You may be able to see the issue by visiting the test server here – https://reddoor.sosquare.com (the testimonials are at the bottom of the page and are sorted randomly). On some of them you'll see the read more links being shown more than once.
Thanks for your help.
You should be able to do it simply in the template with:
Either it doesn't work, or I'm not sure where to put it. It seems to be trying to load a block within a block... because there are multiple text block blocks. Here is the HTML that's being outputted – and the template that's doing it.
the template...
I tried using the Perch conditional tags within the Perch Blocks tag pair but this didn't work.
I added <perch:showall /> to the template which revealed that, even though I'm not calling the quote block in within the blocks tag pair – it's being pulled in anyway but not displayed...
Adding empty blocks to the excerpt / listing template seems to resolve the issue – is this the correct way of doing this Drew?
This is something I'm looking at for 2.9.