I created this helper method:
app\code\Company\Base\Helper\Product.php
public function test($product = null)
{
if (!empty($product)) { exit("TRUE, product is not empty!"); } else { return false; }
}
And injected it into a block, so I can use it there:
THEME\Magento_Catalog\layout\catalog_category_view.xml
<referenceBlock name="category.products.list">
<arguments>
<argument name="test" xsi:type="helper" helper="Company\Base\Helper\Product::test" />
</arguments>
</referenceBlock>
Then I call my helper in THEME\Magento_Catalog\templates\product\list.phtml
<?php /** @var $_product \Magento\Catalog\Model\Product */ ?>
<?php foreach ($_productCollection as $_product) :?>
<?php echo $block->getTest($_product); ?>
This is the template for the category view btw.
But I never get to see "TRUE, product is not empty!".
The same code works great in other locations e.g. on the block product.info.media.image with template Magento_Catalog::product/view/gallery.phtml