Forum

Thread tagged as: Question

Custom content several pages and regions loop

Hi,

I'm trying to retrieve a snippet of data on the main products page, so it lists the 'product groups' with content from the product group page but then also as part of that I want to retrieve the products that are within that group.

/products/
/products/product_group/index.php
/products/product_group/product_name.php
/products/another_product_group/index.php
/products/another_product_group/another_product_name.php

So in basic terms the output would be something like:

Product Group Name, 
Product Group Description, 
Product Group Link

Products within group: 
Product Name 1 & Link, 
Product Name 2 & Link, 
Product Name 3 & Link

Then output the next group until all are listed.

This gets the data from multiple sources but can't fathom how to adjust for my needs. https://solutions.grabaperch.com/architecture/content-from-multiple-pages-and-regions

Any ideas please?

Thanks

Mark Watts

Mark Watts 0 points

  • 6 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

How is your data structured?

Using Blocks and perch:template. So Product Groups and Products are sharing the same code and id's. Reusing the same templates for all the data just products have more detail added obviously. I only need to grab minimal data as above, so what I need is common on both Groups and Products.

<!--* Main heading and introduction and graphic *--> <perch:before> <perch:template path="content/blocks/introduction_block.html" /> </perch:before>

<perch:blocks divider-before="Choose content block to suit you're content as many or little as you want, you can even reorder them.">

<!--* Key Features *-->
<perch:block type="key-feature" label="Key Features">
    <perch:template path="content/blocks/key_features_block.html" />
</perch:block>

<!--* Heading & Text - Option to select h2,3,4,5,6 etc via dropdown *-->
<perch:block type="title-text" label="Heading and Text">
    <perch:template path="content/blocks/text_block.html" />
</perch:block>

<!--* Lists used for things like Features or Benefits *-->
<perch:block type="text" label="Information List">
    <perch:template path="content/blocks/list_block.html" />
</perch:block>

</perch:blocks>

ps. this page won't load for me: https://support.grabaperch.com/formatting

Drew McLellan

Drew McLellan 2638 points
Perch Support

How and where is the group data stored?

All data is added per page and region, NOT list and detail.

Custom content to load and list groups and products on: /products/index.php

Product Groups: /products/group-name/index.php template = Group_detail.html

Products (multiple): /products/group-name/product-name.php template = product_detail.html

Both above share Blocks with some extra for Products, but I don't need to grab any of the extra data.

So on a certain Group page I'm also listing products within that group page like so:

// Get URL segment 1
$segments = explode('/', PerchSystem::get_page());
$group = PerchUtil::html($segments[2]);

    perch_content_custom('Product detail', array(
        'page'=>"/products/$group/*",
        'template'=>'_group_product_listing.html',
    )); 

Does that make sense?

Drew McLellan

Drew McLellan 2638 points
Perch Support

So the process would be:

  1. Get all the group data

  2. Loop through it and get the product data for each group

Is that right?

yes that's correct, so listed on the page it would have X Product Group and associated Products, then the next X Product Group with it's associated products and so on until they are all listed.

Drew McLellan

Drew McLellan 2638 points
Perch Support

Ok, great. At which point are you stuck?

I can get both sets of data e.g. Group & Products but not combine them. As the group and product data is from different regions I don't understand how to load the group from one region and page and then process products in that group data before moving onto the next group. I can only get the data to load separately not combined.

Drew McLellan

Drew McLellan 2638 points
Perch Support

Ok - are you using skip-template to get the data? Can you show me what you have for the groups and we can loop through it.