Forum

Thread tagged as: Question, Problem

Passing category path into array problem

I need a variable passed into an array, however there's something I'm not doing right... little help please.

// Get the page level
perch_content_create('page-level', array(
    'template'   => 'product_level.html',
    'multiple'    => false,
    'edit-mode' => 'listdetail',
)); 

// Save it as a var
$productLevel = perch_content_custom('page-level', array(
    'template'      =>      'product_level_path.html',
    'multiple'      =>      false,
),true);        

echo($productLevel);

if ($varCombninedCategories != NULL) {
    array_push($varCombninedCategories, $productLevel);
} else {
    $varCombninedCategories = array($productLevel);
}

print_r($varCombninedCategories);

$productLevel returns

category/seating-dining/

print_r($varCombninedCategories); returns

Array ( [0] => category/seating-dining/ )

Yet the below does not work:

perch_content_custom('Product-Items', array(
    'template'      =>      'product_item_summary.html',
    'page'          =>      '/products/*',  
    'sort'          =>      'Product-Title',
    'sort-order'    =>      'DESC',                                                     
    'filter'        =>      $filters,
    'category'      =>      $varCombninedCategories,
    'category-match'    =>  'all',
    'paginate'      =>      true,
    'count'         =>      24, 
));

It only works if I use the below:

if ($varCombninedCategories != NULL) {
    array_push($varCombninedCategories, 'category/seating-dining/');
} else {
    $varCombninedCategories = array('category/seating-dining/');
}

However I need to use the variable passed into the array. Anybody know what I'm missing?

James Hazelton

James Hazelton 0 points

  • 5 years ago

product_level.html

<perch:categories id="Category" label="Category" set="category">
    <perch:category id="catTitle" type="smarttext" label="Title" required="true" />
</perch:categories>

product_level_path.html

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

Drew McLellan 2638 points
Perch Support

That should work - what does debug output?

*removed, no longer relevant.

Drew McLellan

Drew McLellan 2638 points
Perch Support

It would be a really good idea to update Perch to the current version.

But then there's this issue: https://forum.grabaperch.com/forum/12-10-2015-perch-input-outputting-blank-select-option-incorrectly-as-bug

Anyway i did, and this thread's issue is still present.

Drew McLellan

Drew McLellan 2638 points
Perch Support

That issue has been fixed.

Solved it, it was spaces " " in the variable.

Just used this to remove spaces:

$productLevel=preg_replace('/\s+/', '', $productLevel);