Forum

Thread tagged as: Question, Problem, Runway

Repeater in collection in related in block!

I think I know the answer to this already but when you have a collection with a repeater and this is used with perch:related tags in a block, the repeater is repeateed (!) in the block and no content is output. Is there any way arounds this? I'm trying to create a collection of galleries or use around a site and a repeater seemed like the best way to allow multiple images to be added to a single collection item.

Collection template

<div class="container">
    <h2 class="sub-heading"><perch:content id="gallery_heading" type="text" label="Gallery heading" size="xl" title="true" /></h2>
    <perch:content id="slug" type="slug" for="gallery_heading" editable="false" indelible="true" suppress="true" />
</div>
<div class="container">
    <perch:repeater type="gallery_images" label="Gallery images" scope-parent="true">
        <div class="gallery">
            <a href="#<perch:content id="parent.slug" />-<perch:content id="parent._block_index" /><perch:content id="perch_item_index" type="hidden" />" rel="modal:open">
                <img src="<perch:content type="image" id="image" label="Image" width="400" height="400" crop="true" quality="60" bucket="gallery" />" alt="<perch:content type="text" id="alt" label="Description (alt)" required="true" />" />
                <div class="caption">
                    <perch:content id="image_caption" type="text" label="Image caption" size="m" />
                </div>
            </a>
            <div id="<perch:content id="parent.slug" />-<perch:content id="parent._block_index" /><perch:content id="perch_item_index" type="hidden" />" class="modal-hider">
                <div class="gallery-box">
                    <img src="<perch:content type="image" id="image" label="Image" width="800" height="800" crop="false" quality="80" bucket="gallery" />" alt="<perch:content type="text" id="alt" label="Description (alt)" required="true" />" />
                    <div class="caption">
                        <p><perch:content id="image_caption" type="text" label="Image caption" size="m" /></p>
                    </div>
                </div>
            </div>
        </div>
    </perch:repeater>
</div>

Block template

<perch:blocks>
    <perch:block type="image_left" label="Img Left">
        <perch:template path="content/_blocks/_image_left.html" />
    </perch:block>
    <perch:block type="image_right" label="Img Right">
        <perch:template path="content/_blocks/_image_right.html" />
    </perch:block>
    <perch:block type="testimonial" label="Testimonial">
        <section class="<perch:content id="background" type="select" label="Background colour" options="Light Grey|light-highlight, Dark Grey|strong-highlight" allowempty="true" required="false" help="Leave this blank for a white background" />">
            <perch:related id="testimonial" collection="testimonials" label="Select testimonial">
                <perch:template path="content/_blocks/_testimonials.html" />
            </perch:related>
        </section>
    </perch:block>
    <perch:block type="cta" label="CTA">
        <perch:template path="content/_blocks/_cta.html" />
    </perch:block>
    <perch:block type="gallery" label="Gallery">
        <section class="<perch:content id="background" type="select" label="Background colour" options="Light Grey|light-highlight, Dark Grey|strong-highlight" allowempty="true" required="false" help="Leave this blank for a white background" />">
            <perch:related id="gallery" collection="galleries" label="Select gallery">
                <perch:template path="content/collections/gallery.html" />
            </perch:related>
        </section>
    </perch:block>
    <perch:block type="stats" label="Statistics">
        <perch:template path="content/_blocks/_stats.html" />
    </perch:block>
    <perch:block type="video" label="Video">
        <perch:template path="content/_blocks/_video.html" />
    </perch:block>
</perch:blocks>

Diagnostics

Perch Runway: 2.8.32, PHP: 5.6.22, MySQL: mysqlnd 5.0.11-dev - 20120503 - $Id: 76b08b24596e12d4553bd41fc93cccd5bac2fe7a $, with PDO
Server OS: Linux, cgi-fcgi
Installed apps: content (2.8.32), assets (2.8.32), categories (2.8.32), collection_3 (2.8.32), perch_blog (5.0), perch_forms (1.8.3), collection_4 (2.8.32), collection_2 (2.8.32), collection_1 (2.8.32)
App runtimes: <?php $apps_list = array( 'content', 'categories', 'perch_forms', 'perch_blog' );
PERCH_RESFILEPATH: /var/sites/m/mojoactive.co.uk/public_html/assets/resources
PERCH_LOGINPATH: /perch
PERCH_PATH: /var/sites/m/mojoactive.co.uk/public_html/perch
PERCH_CORE: /var/sites/m/mojoactive.co.uk/public_html/perch/core
Image manipulation: GD
PHP limits: Max upload 100M, Max POST 100M, Memory: 128M, Total max file upload: 100M
F1: 2edba60ed1f613d6dd804feb202456a2
Resource folder writeable: Yes
DOCUMENT_ROOT: /var/sites/w/www.mojoactive.co.uk.gridhosted.co.uk/public_html
HTTP_HOST: www.mojoactive.co.uk.gridhosted.co.uk
REQUEST_URI: /perch/core/settings/diagnostics/
SCRIPT_NAME: /perch/core/settings/diagnostics/index.php
Caleb Evans

Caleb Evans 1 points

  • 4 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

I think the issue us using a relationship in a block. You can relate items, but not blocks. You should have the relationship defined outside of the blocks.

The testimonials relationship (see above) works perfectly so I thought perhaps it was the repeater inside the block that was causing the problem.

How would I define the relationship outside the block but still allow a gallery to inserted anywhere within the flow of content?

Or can you think of another way I can allow users to add a gallery into a block? The client would like to define a gallery once and then use it in multiple places surrounded by other content. Relating blocks and collections works absolutely brilliantly for this when a repeater is not involved.

I don't think it would be possible with the gallery app. Would it?

Thanks as always.

Drew McLellan

Drew McLellan 2638 points
Perch Support

Are you using the relationship to just import the content?

Yes (If I understand the question correctly). The collection is defined in a different template. That blocks template is used on several different master page regions to allow the client to build a page up however they would like. The default (most common) master page look like this

<?php
perch_content_create('Introduction', [
    'template' => 'introduction.html',
    'multiple' => false
]);
perch_content_create('Main Content', [
    'template' => 'main_content.html',
    'multiple' => false
]);
perch_layout('global/header');

perch_content('Introduction');

perch_content('Main Content');

perch_layout('global/footer');

Main Content region is using the blocks template from above.

Drew McLellan

Drew McLellan 2638 points
Perch Support

Ok, then that sounds like it should work.

Where does it go wrong? This is a demanding one to visualise from a description.