Forum
Can I loop through a multiple item region and within each region use a perch_cus...
Hi,
I am building a website for a real estate company. I have one region called Locations. (there are two of them). Then I have a region called Neighborhoods. On this region I use a dataselect where the admin chooses a location. Lastly I have A Region Called Buildings where there is a dataselect for Neightborhood.
Below is what I'm trying to accomplish.
(the best I have been able to do is loop through the buildings and get just the neighborhood name from the dataselect)
My questions are: 1. I can loop through my neighborhoods (which will include Location Name) and use if statements to get it without the building names. Inside that template is there a way to call a perch_content_custom that would then pull all buildings within the neighborhood? Or 2. If on the Buildings the dataselect was able to provide multiple fields. (The neighborhood name, the neighborhood slig and location name) I would be able to accomplish. I just dont know if that can be done. Is that possible? or 3. Any other suggestions?
Thanks in advance!
<ul>
<li>Location 1 Name
<ul>
<li><a href="NEIGHBORHOOD 1 SLUG">NEIGHBORHOOD 1 NAME</a>
<ul>
<li>BUILDING 1 NAME</li>
<li>BUILDING 2 NAME</li>
<li>BUILDING 3 NAME</li>
</ul>
</li>
<li><a href="NEIGHBORHOOD 2 SLUG">NEIGHBORHOOD 2 NAME</a>
<ul>
<li>BUILDING 4 NAME</li>
<li>BUILDING 5 NAME</li>
<li>BUILDING 6 NAME</li>
</ul>
</li>
<li><a href="NEIGHBORHOOD 3 SLUG">NEIGHBORHOOD 3 NAME</a>
<ul>
<li>BUILDING 7 NAME</li>
<li>BUILDING 8 NAME</li>
<li>BUILDING 9 NAME</li>
<li>BUILDING 10 NAME</li>
</ul>
</li>
</ul>
</li>
<li>Location 2 Name
<ul>
<li><a href="NEIGHBORHOOD 4 SLUG">NEIGHBORHOOD 4 NAME</a>
<ul>
<li>BUILDING 11 NAME</li>
<li>BUILDING 12 NAME</li>
<li>BUILDING 13 NAME</li>
</ul>
</li>
<li><a href="NEIGHBORHOOD 5 SLUG">NEIGHBORHOOD 5 NAME</a>
<ul>
<li>BUILDING 14 NAME</li>
<li>BUILDING 15 NAME</li>
<li>BUILDING 16 NAME</li>
</ul>
</li>
</ul>
</li>
</ul>
Are you using Runway for this?
Hi Drew,
Thanks for responding, I am not using Runway.
The next site I build I plan on using runway, but for this one was on regular.
I think what you need here is the Relationships feature in Runway. Dataselect won't do what you're looking for with multiple fields.
Is it complex to update a current site to Runway? (There are other things already built on this site I would hate to lose)
Is it possible to run a query to the Database and use a while loop for the results? If so I could do that and then use a perch_custom_content inside of the while loop.
It is straightforward to upgrade to Runway, that's really the idea of the two products so you have somewhere to go with sites that need more functionality.
https://docs.grabaperch.com/runway/upgrading/
Here is a post about related content in Runway https://grabaperch.com/blog/archive/rapid-content-relationships-in-perch-runway
Thanks, unfortunately I think that solution would actually be more complex than having it hard coded right now. What about the second option?
Is it possible to run a query to the Database and use a while loop for the results? If so I could do that and then use a perch_custom_content inside of the while loop.
While you could have a go, it's not something we could offer support for.
It won't help you get multiple fields from a dataselect, but you can use the
each
callback option onperch_content_custom()
to retrieve and add additional information to an item before it goes to the template.See "Specifying an item callback function"
https://docs.grabaperch.com/docs/content/perch-content-custom/
In case anyone was wondering I was able to accomplish this using the "skip-template" feature of custom content and just looped through the array of the outside neighborhood (which has the location information) I was able to use an if statement to see if a new location and then inside of the loop I looped I ran another custom content and looped through buildings associated eith that neighborhood. My code is below if its helpful for anyone .