here is my block file:
path:-VendorModuleBlock
<?php
namespace VendorModuleBlock;
class Product extends MagentoFrameworkViewElementTemplate
{
protected $_productCollectionFactory ;
public function __construct(
MagentoBackendBlockTemplateContext $context,
MagentoCatalogModelResourceModelProductCollectionFactory $productCollectionFactory,
array $data = []
)
{
$this->_productCollectionFactory = $productCollectionFactory;
parent::__construct($context, $data);
}
public function getProductCollection()
{
$collection = $this->_productCollectionFactory->create();
$collection->addAttributeToSelect('*');
return $collection;
}
}
here is my template file:
path:-VendorModuleviewfrontendtemplates
<?php
$collection = $block->getProductCollection();
print_r($collection);
?>
can any one help me with this part?
Thanks in Advance!
2
Answers
Try
$block->getProductCollection()->getItems()
in the template. It returns an array of products.