We are transitioning over to a new forum platform. Please post new issues there. Existing threads will be dealt with here unless you choose to move them over. Visit the new forum
Forum
Passing vars into individual collection items
Hi Guys,
I have a list page that shows all items for a collection. Individually I am able to pass in a perch var, like so:
if (perch_get('product_slug')) {
$result = perch_collection('Products', array(
'template' => 'shop/product',
'filter' => 'product_slug',
'match' => 'eq',
'value' => perch_get('product_slug'),
'count' => 1,
'skip-template' => true,
'return-html' => true,
));
PerchSystem::set_var('total_price', ($result[0]['product_price']+$result[0]['product_postage'])*100);
}
However, on the main page where all the items are listed. How can I pass/set this var individually for each collection item?
perch_collection('Products', [
'template' => 'shop/_teaser',
]);
Thanks, Terry
Want to reply to this thread?
Login with Perch
Use an
each
callback. See the section "Specifying an item callback function"https://docs.grabaperch.com/docs/content/perch-content-custom/
I have tried this;
But it sets the same amount for each product. Rater than each one individually. My code might be wrong, any pointers?
Thanks Drew.
Terry
You need to modify
$item
and then return it, so instead of this:do this:
Thanks Drew :-)