Collection Item Print ProductRegion.Description only if Product.Description is not set

My question is this…How do I print the field of one collection item (a Product collection item) only if the field of another collection item (a ProductRegion item) is not set?

The longer version of my question:

I have a collection called Product with the field Description. I also have a collection called ProductRegion. The ProductRegion also has a field called Description. A product can have many ProductRegion, a ProductRegion can have many Product. Eg. A computer can be associated with Canada, Mexico, Egypt, and Canada can have computer, keyboard, mouse.

I went to the ProductRegion template. I put in a Collection List and bound it to the source Product. For each collection item, I created a text block and bound it to Product.Description. I set a condition to print Product.Description only if it exists.

Then I placed a second text block into the product collection item list. But I can’t find the ability to bind the textblock to the description of the ProductRegion. How do I do this? Additionally, I only want ProductRegion.Description to appear only if Product.Description is not set.

As example of what i’m trying to accomplish: If computers are sold in canada, i want to see the description of the computer. If there is no description for the computer, then fall back to the default description in canada’s description (and not the description from mexico, egypt, etc…)

What did I do wrong?

To understand what you’ve setup, you’ll need to create & share the readonly designer link to the page you’re designing.

In general you’d use refs or multi-refs for this, and then those become available as part of your collection list filtering. In some cases they’ll also be available for conditional visibility, but you may need custom code there if it’s more of a tangential connection.

Another way is to build an Xref table.

Product - list of products
Region - list of regions
ProductRegion - one row for every product-region combination

This gives a ton of flexibility because it’s easy to pull the data you want from either end ( Products in Region X, Regions product X is available in. Plus metadata becomes easy, like Region-specific product inventories or pricing.

1 Like

Oh ok, i’m really new to webflow. Heres the read only link I think? Webflow - Research's Top-Notch Site

This is my experimental site.

I think my problem analogous to this php code

/*
DB SCHEMA:
Product: ProductId, Name, Description
ProductConfiguration: ProductId, Region, Description
*/
$country = 'canada'; // Assuming I visited the url https://site.com/productregion/canada 
$results = mysql_fetch("SELECT Name,Description FROM Product WHERE ProductId IN (SELECT ProductId FROM ProductConfiguration WHERE Region = '$country')");
foreach($results as $row) {
 echo $row['Product.Description'] ? $row['Product.Description'] : $row['ProductConfiguration.Description'];
}


ERROR: ProductConfiguration.Description is not set

The error occurs because I don’t know how to select the ProductConfiguration.Description while looping through the Product collection

Webflow / browsers don’t run php code and I’m not sure what you’re trying to describe there. WF’s data rendering and filtering are all settings on your collection list.

Currently you have two collections with 2 multirefs, which will work but means you always have to update at least two separate things to keep them in sync.

You can’t. Elements inside of the collection list can only be data-bound to fields that the collection list itself is CMS-bound to.

You’d need to use javascript here to detect the empty description, and create one from your page-level region data.

1 Like

OK yeah, that’s what I was hoping to avoid, which is the problem described in my php-sql pseudo code. I was hoping that elements inside a collection list has access to fields from other collections via something similar to “SQL JOIN”… like a “SELECT * FROM Product INNER JOIN ProductConfiguration ON ProductConfiguration.ProductId = Product.ProductId.” And then borth Product.Description and ProductConfiguration.Description can be made available in the webflow collection list.

But OK. I’ll create some bandaid solutions for situations like these. Thanks!

@memetican , oh actually wait…that makes me wonder. Does webflow have someting like an SQL View or an SQL StoredProcedure? LIke you can create a “view” on top of your collections? Then have the webflow collection list iterate over the results of the “view”?

If you use my XRef schema design above, it will work because you can link into fields of a single-ref connected item. That way your product collection list is both filtered to the current region, and can access fields of that region through the single-ref.

No.

1 Like

Here’s a quick demo-