Forum
Merging Two Regions
Hello,
I have been struggling with this for about a week now, so hopefully someone can help me out.
I have two regions, one is called Profile
and is used on all classroom pages - a page per classroom - where regions are referenced from a Master Page template. The other region is called Faculty
and is located on the faculty.php
page, which lists all the faculty members, each with a link to their own classroom page.
The Profile
region contains classuser, email, _page, banner
fields and ID's.
The Faculty
region contains name, email, room, title
fields and ID's.
Now I have individual classroom pages - a page per classroom, as mentioned above. Then I have a Classrooms
page where I want to display a list of all the individual classroom pages. The data I need is in either the Profile
or Faculty
regions, but if you notice, both regions have an email
ID.
How can I merge these two regions, using the email
ID as the common variable, and then use the fields from both regions in a single template on the Classrooms
page? Sort of like a directory of the classroom pages and their corresponding faculty.
Code for Classrooms
Page:
$jmUsers = perch_content_custom(array('Profile','Faculty'), array(
'page' => array('/classroom/*','/faculty.php'),
'template' => '_classdisplay_all.html',
'sort' => 'room',
'sort-order' => 'ASC'
));
Template for Classrooms
page:
<div class="rmEntry">
<h3><a href="<perch:content id="_page" />">Classroom <perch:content id="room" /></a></h3>
<div class="banner">
<img src="<perch:content id="banner" />" alt="Class Banner" />
</div>
<div class="detail">
<p><perch:content id="classuser" />: <perch:content id="title" /></p>
</div>
</div>
The output I'm getting from this code and template, displays each classroom on the Classrooms
page, but only the fields from the Faculty
region show up. Any ideas, suggestions...?
Thanks, Joshua
I would turn it around. Have a region of your classrooms on the classrooms page. Use a
dataselect
orrelated
field type to pull the classroom information into the other regions where you need it.That does sound like a much better solution and I may have considered it before, but here's the problem.
The content of each
Classroom
page is dynamic in a sense, and any changes made on an individual page would reflect on theClassrooms
page.So if, for example, the faculty member changes the way their name is displayed (eg. Mr. Smith as opposed to John Smith), or add/change their classroom page banner, they would do this from the
Profile
region of their own classroom page. Those changes would then need to reflect on theClassrooms
page. I was using a similar method using the following code, but only usingclassuser, banner, _page
ID's from the `Profile' region.My goal was to merge the two regions somehow, using an
email
ID as a common value, so I could addroom,title
data on theClassrooms
page, without having to duplicate that data in a new region on theClassrooms
page.On the individual classroom pages, I used the following to pull data from the
Faculty
region on thefaculty.php
page, where theemail
ID was equal to theemail
ID in theProfile
region of each classroom page:Then I used the set_vars in a template to display the data as needed.
I figured I could use the same concept with the
Classrooms
page. The difference though is that with each classroom, the set_vars data is filtered by theemail
ID, so each page pulls only the faculty data that corresponds to their classroom. If only there was a way to use PerchSystem::set_vars, but without filtering for a single classroom page result, but instead an array of classroom pages. I don't know if I'm explaining myself well, but hopefully you see what I'm trying to do?Thanks, Joshua
I got it!
I was hoping for something more simple, but I just want to let you know that I was able to figure it out. Pheww!!!
First, I gathered the data from one region:
Then I used a foreach loop to pull the values I needed for each classroom page, placed the email value in a variable to reference in both regions, used PerchSystem to pass the variables into my template, and finally created a template for the other region, passing in the variables I had set, and filtering by my
email
variable:This was my final working template:
You're advice though will definitely come in handy for another project I'm working on...thank you!