Forum

Thread tagged as: Question

Listing pages based on the value of a field

I am putting a property listing site into perch.

On the property listing page it needs to list all of the properties in tabs based on how many bedrooms each has.

Each property is set up as a sub-page of 'Property Listings', screenshot: https://bit.ly/2sxjj6K

In the perch region within the Property Details region I have the following content:

<perch:content id="bedrooms" type="select" label="Number of bedrooms"
  options="2 Bedrooms, 3 Bedrooms, 4 Bedrooms, 5 Bedrooms, 6+ Bedrooms" allowempty="false" required="true" />

So how can I pull out pages based on value of this region to put them under the correct tab?

For reference this is a demo of how the page needs to function: https://motspa.webflow.io/property-listing

John Hobson

John Hobson 0 points

  • 4 years ago
Duncan Revell

Duncan Revell 78 points
Registered Developer

You could start by slightly changing your options list to

options="2 Bedrooms|2, 3 Bedrooms|3, 4 Bedrooms|4, 5 Bedrooms|5, 6+ Bedrooms|6"

so the number values are passed to the template.

Then in your template you can use

<perch:if id="bedrooms" value="2">
...
</perch:if>
<perch:if id="bedrooms" value="3">
...
</perch:if>
etc
etc

Thanks Duncan,

So how do I get perch to just look at the pages that are nested under property listing and then access the variables from those listings in the template?

From looking at the docs I think that I would need to use perch_content_custom, is that right?

Drew McLellan

Drew McLellan 2638 points
Perch Support

Right. You could use a path option to set a path like /properties/*

So I have the following:


perch_content_create( '2 Bed Properties' ); perch_content_custom( '2 Bed Properties', array( 'path' => '/properties/*', /*'filter' => 'bedrooms', 'match' => 'eq', 'value' => '2',*/ 'template' => 'single_property_listing.html' ) );

But it seems that nothing is being returned.

You can see from this screenshot of the directory structure that there is content in the /properties/ directory and that the single_property_listing.html template exists.

That template looks like this:

<div class="list-wrap w-clearfix">
    <div class="sum-left"><img class="sum-thumb" src="images/img-sum01_1.jpg">
    </div>
    <div class="sum-right">
        <h1 class="sum-title"><perch:content id="address" type="text" label="Address"/></h1>
        <p class="sum-summary"><perch:content id="summary" type="textarea" markdown="true" editor="markitup" label="Summary" suppress="true"/></p>
        <p class="sum-price"><perch:content id="price_details" type="text" label="Price details" help="e.g. £92.00 per person per week" required="true"/></p>
        <div class="w-clearfix">
            <div class="sum-ico-wrap w-clearfix"><img class="sum-ico" src="images/Bedroom-small-icon.png" width="45">
                <div class="sum-ico-text">
                    <p class="sum-summary"><perch:content id="bedrooms" type="select" label="Number of bedrooms"
                                                   options="2 Bedrooms|2, 3 Bedrooms|3, 4 Bedrooms|4, 5 Bedrooms|5, 6+ Bedrooms|6" allowempty="false" required="true"/></p>
                </div>
            </div>
            <div class="sum-ico-wrap w-clearfix"><img class="bath sum-ico" height="27" src="images/Bathroom-small.icon.png" width="45">
                <div class="sum-ico-text">
                    <p class="sum-summary"><perch:content id="bathrooms" type="select" label="Number of bathrooms"
                                                   options="1 Bathroom, 2 Bathrooms, 3 Bathrooms, 4 Bathrooms, 5 Bathrooms, 6+ Bathrooms" allowempty="false" required="true"/></p>
                </div>
            </div>
        </div>
        <a class="button w-button" href="property-detail.html">VIEW DETAILS</a>
    </div>
</div>

And a few screenshots showing how I have it configured:

Any ideas why this isn't working?

Drew McLellan

Drew McLellan 2638 points
Perch Support

What's with the stray opening comment on this line?

/*'filter' => 'bedrooms',

That's commenting out the filters as I'd just like to get it to return anything for now. There's the closing comment 3 lines down. Regardless, it doesn't work even without the commented out section

<?php
                    perch_content_create( '2 Bed Properties' );
                    perch_content_custom( '2 Bed Properties', array(
                        'path'       => '/properties/*',
                        'template'   => 'single_property_listing.html'
                    ) ); ?>
Drew McLellan

Drew McLellan 2638 points
Perch Support

Ah ok! Couldn't see the closing comment for some reason!

What does debug tell you?

Ah, just discovered the debug functionality - handy!

It says:

No matching content regions found. Check region name (2 Bed Properties) and page path options.

Does the perch_content_create not define the region so that it can then be used by perch_content_custom?

Drew McLellan

Drew McLellan 2638 points
Perch Support

Yes, that's how it works. Can you see the regions in the control panel?

I can't see the '2 Bed Properties' region in the control panel but I can see the other region defined on the page by:

<?php perch_content( 'Page Title' ); ?>

Screenshot: https://bit.ly/2sOSICj

I'm wondering if I should have added another content region and then put the following code

<?php
perch_content_create( '2 Bed Properties' );
perch_content_custom( '2 Bed Properties', array(
'path' => '/properties/*',
'template' => 'single_property_listing.html'
) ); ?>

within a template? But then you'd have a template referencing a template which doesn't seem quite right.

Drew McLellan

Drew McLellan 2638 points
Perch Support

I think you probably need to rewind a step or two. This sounds confusingly complicated. What are you trying to achieve?

I just want to have a number of properties that are listed based on the number of bedrooms that each has, like on this page: https://motspa.webflow.io/property-listing

Right, I think i need to use repeating regions and not multiple pages for the properties. I will just go and re-write that and see where I get to.

Finally got this sorted by using repeating regions. For the individual property pages I used a querystring so that I could filter on _id

perch_content_custom( 'Properties', [
                        'page'     => '/properties.php',
                        'template' => '_property_detail.html',
                        'filter'   => '_id',
                        'match'    => 'eq',
                        'value'    => perch_get('id')
                    ] );