Forum

Thread tagged as: Question

Retrieving content from multiple regions

I have a page that i want to display an image a information from various pages (similar to product listing) i have a image in one region and a brif overview in another. I have used perch_custom_content to retrieve from both regions.

<?php perch_content_custom(array('Lift main Image','Lift Specs'),  array(
    'page'=>'*',
    'template'=>'lift-list.html',
    'sort-order'=>'ASC',
)); ?>

In the template i have both bits of info that i want to display in one div (the image and the informaion) But on my page it searches both template for each of the areas. (so i have two div's , one with a blank picture and the information and another with the image and blank information)

Is there a way to only search and display the content if it is there (so i would have 1 div with an image and content)

John Robinson

John Robinson 0 points

  • 7 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

What does your template look like?

<div class="access-product-cat"> <a href="<perch:content id="_page" />">

<img class="scale" crop="true" src="<perch:content type="image" id="image-main" width="162px" height="243px" crop="true"/>" />

<p style="text-align:center;"><perch:content type="text" id="alt" label="Description" required="true" help="e.g. Photo of MD John Smith with his best wig on" title="true" /><br/>

<p style="text-align:center;"> Working Height: <perch:content id="working" type="text" label="Working Height" /></p>

</p> </a>

</div>

Drew McLellan

Drew McLellan 2638 points
Perch Support

So could you do something like

<perch:if exists="image-main">
    <img class="scale" crop="true" src="<perch:content type="image" id="image-main" width="162px" height="243px" crop="true"/>" />
<perch:else />
    <div> ... the rest ... </div>
</perch:if>

I cant seem to get this to work, as they are still showing in separate div's, where as i would need all parts to show in "<div class="access-product-cat"> ", the image and description are in the same region and the working height is in another?

Drew McLellan

Drew McLellan 2638 points
Perch Support

What output are you trying to get?

Is there a reason the image is in a different region to its associated content?

All the content is to do with one "product", and is all on one page, but is split up in to different regions (for ease and for styling).

on a seperate page I am going to link to the various "product" pages. and from that page i want to pull the image and some specs (which appear in different regions but on the same page).

So in essence i would have:

<div> image - region a

Image title - region a

spec information - region b </div>

reapeated for each of the pages I have.

Drew McLellan

Drew McLellan 2638 points
Perch Support

I don't think the way you've structured it will work well for what you're now trying to do. Possible solutions are:

1) Structure your products into atomic regions

2) Use the navigation functions to get your list of pages, then loop through and output the regions from those pages

Right ok, so in the future all information would need to be in the same region?

could you explain these further at all?

Drew McLellan

Drew McLellan 2638 points
Perch Support

If you have a conceptual item like a product, it's best to store this in a region of products. You can then use different templates to output that in different ways, but you have always go a single, tidy, self-contained product unit to work with.

This sound like what we would need, sorry is there any documentation on the best ways to do this.

Thank you for your help.

Drew McLellan

Drew McLellan 2638 points
Perch Support

Documentation about which bit?

You can then use different templates to output that in different ways, would this mean that i could use more that one template within one region?

just not too sure how i would achieve what you described?

Drew McLellan

Drew McLellan 2638 points
Perch Support

With perch_content_custom() you can specify a template option to output the region using a different template.

https://docs.grabaperch.com/docs/content/perch-content-custom/

Thanks, i have used this before, would this just mean all the styling for the separate part of the page would have to go in the one template? with all areas being in one region rather than having them split up.

Drew McLellan

Drew McLellan 2638 points
Perch Support

I wouldn't normally expect there to be any styling in your template.

so at the moment i have 4 templates, which relate to 4 regions i have on a page, these are styled using divs ect. would this then all need to be combined into one template.

Drew McLellan

Drew McLellan 2638 points
Perch Support

For editing, yes, but not for display. Edit with one template, display with others.

Thank you, i have finally got, got there in the end!!!