Forum

Thread tagged as: Question, Problem, Field-Types

Dataselect not working for multiple pages

Hi im trying to use a data select to get content from a region that is on multiple pages. This is the code im trying to use:

<perch:content id="branch" type="dataselect" label="Branch" page="/branches/*" region="Branch Map" options="city" />

So im trying to pull in the content for city thats in the Branch Map region for all the pages under the directory /branches but i cant seem to get it to pull anything in.

I can get it to pull in the content if i put the full file path for one of the branches like page="/branches/birmingham/index.php" but as the client will be adding in more branches and there is quite a few of them it needs to be pulling it in from all the ones under /branches/.

Debug from page template with data select on it:

Debug Message
[1] SELECT u.*, r.* FROM perch2_users u, perch2_user_roles r WHERE u.roleID=r.roleID AND u.userEnabled=1 AND u.userID=1 AND u.userHash='691d51a129be8dda0938de7f76ee6d43' LIMIT 1
UPDATE perch2_users SET userHash='7af3d5d47b39c765184988c2bbb70322' WHERE userID='1'
[29] SELECT p.privKey FROM perch2_user_privileges p
[10] SELECT * FROM (SELECT DISTINCT settingID, settingValue, userID FROM perch2_settings WHERE userID=1 OR userID=0 ORDER BY userID DESC) AS settings GROUP BY settingID, settingValue, userID
[1] SELECT * FROM perch2_content_regions WHERE regionID=528 LIMIT 1
[1] SELECT * FROM perch2_pages WHERE pageID='126' LIMIT 1
[1] SELECT * FROM perch2_content_items WHERE regionID=528 AND itemRev=4 ORDER BY itemOrder ASC
[1] SELECT * FROM perch2_content_items WHERE regionID=528 AND itemRev=4 ORDER BY itemOrder ASC
Using template: /templates/content/staff_info.html
Form not posted or did not validate
[1] SELECT * FROM perch2_content_regions WHERE regionPage='*' AND regionKey='Branch Map'
Queries: 10
Memory: 3.8204
ewe agency

ewe agency 0 points

  • 5 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

That's beyond what dataselect is capable of. It sounds more like you need the Relationships feature in Runway.

Ahh i had a feeling that might be a problem, no worries i will upgrade then cheers!

Following on from this yesterday ive upgraded my site to runway and i am trying to get the functionality to work.

Ive managed to create a collection and add the branch name and then be able to select the branches that each staff member will appear on but i cant figure out how to output the staff members who correspond with the branch to output onto the page.

Tried using a region with a perch related in it and also tried outputting the collection using a template

Rachel Andrew

Rachel Andrew 394 points
Perch Support

Can you show us the code you have tried?

This is the perch:related bit:

<perch:related id="branch" collection="Branch" label="Branch">
      <perch:content id="city" type="hidden" />
</perch:related>

The php i tried:

<?php
            perch_collection('Branch', [
              'filter' => 'branch.city',
              'match'  => 'eq',
              'value'  => 'Birmingham',
            ]);
          ?>

and the code in a perch region i made:

<perch:related id="staff" collection="Branch">
  <div class="staff">
      <h5><perch:content id="staffname" /></h5>
      <p><perch:content id="staffposition" /></p>
      <a href="<perch:content id="_page" />">View Profile <span></span></a>
  </div>
</perch:related>

I think its not working because the content im trying to pull in through the collection/relationship isnt in the collection but in another region. But then to add every staff member in perch as a page then also in the collection would be more work than just adding them in normally and calling them in via a perch_custom_content

Drew McLellan

Drew McLellan 2638 points
Perch Support

So you have a collection of branches, and on the staff page you want to list all branches that the current staff member is related to? Is that right?

Yeah i have a collection of branches but it should be the other way round so on the branch page i want to list all the staff who work there, so for the Leeds branch there should be a list of staff x,y,z that work at that branch.

But then some people work at more than one branch so will appear on more than one branch page.

So do i need to make a collection of staff members then put the perch:related on the branch page and do it that way?

Drew McLellan

Drew McLellan 2638 points
Perch Support

Yes, you need a collection of branches and a collection of stuff. Then relate the staff to the branches.

To get a list of branches for a given staff member (Ted Jones with slug of ted-jones):

perch_collection('Branches', [
    'filter' => 'staff.slug',
    'value' => 'ted-jones',
]);

Right i think im starting to get it now.

Ive managed to get the staff member to display on the branch page but the issue now is its displaying on all branch pages, not just the specific ones ive selected using the perch relation

Drew McLellan

Drew McLellan 2638 points
Perch Support

Ok - can you show me what code you've got?

The perch related:

<perch:related id="branch" collection="Branch" label="Branch">
      <perch:template path="content/branch_map.html" />
</perch:related>

The output from the collection:

          <?php
              perch_collection('Staff', [
                  'filter' => 'city',
                  'template' => 'branch_test.html'
              ]);
           ?>

Branch_test.html:

<div class="staff">
    <h5><perch:content id="staffname" /></h5>
    <p><perch:content id="staffposition" /></p>
    <a href="<perch:content id="_page" />">View Profile <span></span></a>
</div>

Just noticed i forgot to add staff.city in the filter but still not working

Drew McLellan

Drew McLellan 2638 points
Perch Support

When you set filter you also need to set value.

  • filter: the field to field by
  • match: the type of comparison (eq by default for equal to)
  • value: the value to compare that field to

Just added the value that the staff.city is equal to in the perch relation but it doesnt output anything still

Drew McLellan

Drew McLellan 2638 points
Perch Support

Can you show me the code that isn't working? It's hard to debug with just a description of what you've tried.

Yeah sure this is the code im using to try output the staff info:

          <?php
              perch_collection('Staff', [
                  'filter' => 'staff.city',
                  'template' => 'branch_test.html',
                  'value' => 'Birmingham',
              ]);
           ?>

And this is the perch relationship code which in perch has 'Birmingham" selected from the city ID:

<perch:related id="branch" collection="Branch" label="Branch" value="true" suppress="true">
      <perch:content id="city" type="text" />
</perch:related>
Drew McLellan

Drew McLellan 2638 points
Perch Support

The ID of your repeater is branch, so you'd need to use branch.city to filter.

Ahhh, excellent that is working now cheers!

But how do i get to the page created in the collection using perch_custom_content its normally

<a href="<perch:content id="_page" />"></a>

Ive been through this video but it doesnt really explain how to get to the article pages…

https://grabaperch.com/blog/archive/related-content-in-perch-runway

Drew McLellan

Drew McLellan 2638 points
Perch Support

Normally you'd derive the page from data in the collection. What format do your page URLs take, and what data is available to construct the correct URL?

Well i currently have the slug pulling in the staff first name and last name, so the url is be /branches/firstname-lastname

<perch:content id="staffslug" type="slug" editable="true" indelible="true" label="Slug" surpress="true" for="staffname" />

And on the branch page where the perch_collection is being outputted on the URL pattern i have: "branches/[slug:staffslug]"