Forum

Thread tagged as: Error

Template returns catPath with whitespace

Hello,

Just reporting a little problem I encountered today. I've set up a template to allow my client to select a default category for a page.

Template:

<perch:categories id="category" set="products" label="Category">
    <perch:category id="catPath" />
</perch:categories>

On the master page, this is the part that uses the template:

perch_shop_products([
    'template' => 'products/product_list.html',
    'category' => perch_content('Default Category', true),
    'count' => 9,
]);

This took the whitespace in the template file into account (so didn't display the results):

SELECT DISTINCT idx.itemID FROM perch2_shop_index idx
JOIN perch2_shop_products main ON idx.itemID=main.productID
AND idx.itemKey='productID' 
AND ((idx.indexKey='_category'
AND idx.indexValue LIKE '\r\n   products/collection-iv/\r\n%' 
OR idx.indexKey='_category' 
AND idx.indexValue='\r\n    products/collection-iv/\r\n'))

Solution 1: stripping whitespace from the path

perch_shop_products([
    'template' => 'products/product_list.html',
    'category' => trim(perch_content('Default Category', true)),
    'count' => 9,
]);

Solution 2: removing the whitespace in the template file

<perch:categories id="category" set="products" label="Category"><perch:category id="catPath" /></perch:categories>

Both solutions return the expected results

SELECT DISTINCT idx.itemID FROM perch2_shop_index idx 
JOIN perch2_shop_products main ON idx.itemID=main.productID
AND idx.itemKey='productID' 
AND ((idx.indexKey='_category' 
AND idx.indexValue LIKE 'products/collection-iv/%' 
OR idx.indexKey='_category' 
AND idx.indexValue='products/collection-iv/'))
Hussein Al Hammad

Hussein Al Hammad 105 points

  • 5 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

That's expected behaviour. If there's whitespace in your template, we don't mess with it.

Hussein Al Hammad

Hussein Al Hammad 105 points
Registered Developer

Oh ok fair enough! Easy to deal with anyway.

Thanks Drew!