Forum

Thread tagged as: Problem

Multiple Blocks With Repeaters

Hi guys,

I'm creating a blocks template, and several of the blocks have repeaters in them (as well as before and after tags).

The trouble is that if I put these blocks on the same page, the <perch:after> tags seem to be being ignored, meaning that the page and all content following the first block is output into the divs inside each block.

Here is the relevant part of my template:

<perch:block type="contact" label="Contact Us">
    <perch:before>
        <div class="full-height <perch:content id="background-colour" />-page" id="contact-section">
            <div class="contact">
                <perch:content id="fw-text" type="textarea" textile="true" editor="markitup" size="xl" />
                <div class="loc-hold">
    </perch:before>

    <perch:repeater id="location" label="Location">
                    <div class="location">
                        <h3><perch:content id="loc-name" label="Location Name" type="text" /></h3>
                        <perch:content id="loc-adr" label="Address" type="textarea" textile="true" editor="markitup" size="s" />
                    </div>
    </perch:repeater>
    <perch:after>
                </div>
            <a href="<perch:content id="button-link" label="Button Link" type="text" />"><perch:content id="button-text" label="Button Text" type="text" /></a>
            </div>
        </div>
    </perch:after>
</perch:block>

<perch:block type="btl-butt-str" label="Big Text Left & Button | Right Text">
        <div class="full-height <perch:content id="background-colour" />-page">
            <div class="text-holder">
                <div class="left-half">
                    <perch:content id="fw-text" type="textarea" textile="true" editor="markitup" size="l" />
                    <a href="<perch:content id="button-link" label="Button Link" type="text" />"><perch:content id="button-text" label="Button Text" type="text" /></a>
                </div>
                <div class="right-half">
                    <div class="right-half-text">
                        <perch:content id="right-text" type="textarea" textile="true" editor="markitup" size="l" />
                    </div>
                </div>
            </div>
        </div>
</perch:block>

<perch:block type="img-band" label="Image Band">
        <perch:before>
        <div class="half-height <perch:content id="background-colour" />-page">
            <div class="image-band">
        </perch:before>
        <perch:repeater id="image-rep" label="Image">
            <img src="<perch:content id="image-img" label="Image" type="image" />" alt="<perch:content id="alt" label="ALT tags" type="text" />" />
            </perch:repeater>
        <perch:after>
            </div>
        </div>
        </perch:after>
</perch:block>

Thanks, Harry

Harry Ray

Harry Ray 0 points

  • 4 years ago
Duncan Revell

Duncan Revell 78 points
Registered Developer

Individual perch:block items can't have before and after tags.

You can only use before/after with the surrounding perch:blocks tag.

https://docs.grabaperch.com/templates/blocks/

Hi Duncan,

Thanks for the help - how would you recommend handling this?

Should I be looking into using template includes inside the blocks?

Drew McLellan

Drew McLellan 2638 points
Perch Support

Before and after tags only apply to repeating/looping structures.

Hi Drew,

Thanks - so how would you recommend that I handle this template? I need the blocks functionality, but some of the blocks need to contain repeaters - which is why this is laid out the way it is.

Drew McLellan

Drew McLellan 2638 points
Perch Support

The blocks can contain repeaters, and the repeaters can contain before and after sections.

Which is what I've done, however, the problem is that when I use multiple blocks on the same page, the <perch:after> tags seem to be being ignored, meaning that the page and all content following the first block is output into the divs inside each block.

Drew McLellan

Drew McLellan 2638 points
Perch Support

That's not what you've done above. If you've changed your template since and it's not working, perhaps post it again so we can see.

Solved!

I'd put the before and after tags outside of the repeater - I've always done it this way, but I guess it was incorrect.

Solved by placing tags inside the repeater pair - thanks Drew!