Problems, need help? Have a tip or advice? Post it here.
8 posts Page 1 of 1
Hello,

I'm trying to use a custom_field to filter out images that are categorised in a repeatable, the problem is the category is within the repeatable and I don't know how to use the custom_field in that way.

I've tried to use an if statement within the repeatable, but because of the limit it's still looping through the other entries and not showing the specific ones it should.

Code: Select all
                        <cms:pages masterpage='gallery.php' custom_field='category=home'>
                            <cms:show_repeatable 'gallery' limit='3'>
                                <figure>
                                    <img src="<cms:thumbnail image width='450' height='450' />" alt="" width="450" height="450" class="rounded">
                                </figure>
                            </cms:show_repeatable>
                        </cms:pages>


Thanks,

Chris
Hi,

Could you please post the full definition of your repeatable-region?
Ok, so this is my template:

Code: Select all
<cms:template title='Gallery'>
    <cms:repeatable name='gallery' label="Gallery">
        <cms:editable name='image' type='image' label="Main Image" width="1200" />
        <cms:editable
            name='thumb'
            type='jcropthumb'
            assoc_field='image'
            label="Thumbnail"
            width='450'
            height='450'
            quality='90'
        />
        <cms:editable
            name="category"
            label="Category"
            opt_values='Daffodil Room=daffodil-room.php | Sunflower Room=sunflower-room.php | Buttercup Room=buttercup-room.php | Bluebell Room=bluebell-room.php | Rose Room=rose-room.php | Educare Garden=educare-garden.php | Home Page=home | Misc=misc'
            type='dropdown'
        />
    </cms:repeatable>
</cms:template>


So for different pages, different images will appear depending on the category allocated. Then on the relevant page, 3 images are displayed from the gallery.
I think what you are trying to achieve could be done in a more efficient manner by using 'relations'; please see the following thread for an example of "Nested Gallery on each page"-
viewtopic.php?f=8&t=8559

If, however, you choose to go with your original solution, the comparison you are looking for can be done as follows -
Code: Select all
<cms:pages masterpage='gallery.php'>
    <cms:show_repeatable 'gallery'>
        <cms:if category eq 'home'>
            <figure>
                <img src="<cms:thumbnail image width='450' height='450' />" alt="" width="450" height="450" class="rounded">
            </figure>
        </cms:if>
    </cms:show_repeatable>
</cms:pages>

To show only 3 images, we can add a counter to the code as follows -
Code: Select all
<cms:pages masterpage='gallery.php'>
    <cms:set my_count='0' />
   
    <cms:show_repeatable 'gallery'>
        <cms:if category eq 'home' && my_count lt '3'>
            <figure>
                <img src="<cms:thumbnail image width='450' height='450' />" alt="" width="450" height="450" class="rounded">
            </figure>
           
            <cms:incr my_count />
        </cms:if>
    </cms:show_repeatable>
</cms:pages>

Hope this helps.
This is great thank you.

One last thing - I'm displaying 3 gallery images in one place on the page and another 3 further down the page, how would I offset the second batch so that the same images aren't shown twice?
I think the following code should do that -
Code: Select all
<cms:pages masterpage='gallery.php'>
    <cms:set my_count='0' />
   
    <cms:show_repeatable 'gallery'>
        <cms:if category eq 'home'>
            <cms:if my_count ge '3' && my_count lt '6'>
                <figure>
                    <img src="<cms:thumbnail image width='450' height='450' />" alt="" width="450" height="450" class="rounded">
                </figure>
            </cms:if>
           
            <cms:incr my_count />
        </cms:if>
    </cms:show_repeatable>
</cms:pages>

Please try and let me know.
Amazing, thank you so much.
You are welcome :)
8 posts Page 1 of 1
cron