Magento Asked by Andrej Wasemiller on December 24, 2020
How in Block
app/code/Name/Name/Block/Rewrite/TopMyMenu.php
a productcollection of template
“vendor/magento/module-catalog-widget/view/frontend/templates/product/widget/content/grid.phtml”
render?
$productCollection = $this->categoryFactory->create()->getCollection()
->addAttributeToSelect('*')
->addAttributeToFilter('is_active', 1)
->setOrder('position', 'ASC')
->addIdFilter($category->getChildren());
$html = $produCtcollection->toHtml(); ?????
maybe I asked wrong... This solution I was looking for:
...
getBlockProductsHtml($productCollection);
...
public function getBlockProductsHtml($collection) {
$html = '';
$html = $this->_layout
->createBlock('MagentoCatalogWidgetBlockProductProductsList')
->setTemplate('Namespace_Module::html/products-grid.phtml')
->setData('product_collection', $collection)
->toHtml();
return $html;
}
or
->setTemplate('Magento_CatalogWidget::product/widget/content/grid.phtml')
thanks to all
Answered by Andrej Wasemiller on December 24, 2020
toHtml()
return block's html output
Process
vendormagentoframeworkViewElementAbstractBlock.php
public function toHtml()
{
/* dode */
$this->_beforeToHtml();
$html = $this->_toHtml();
$this->_saveCache($html);
/* dode */
return $html;
}
Next this goes to vendormagentoframeworkViewElementTemplate.php
protected function _toHtml()
{
if (!$this->getTemplate()) {
return '';
}
return $this->fetchView($this->getTemplateFile());
}
Renders block html. and $this->fetchView
function retrieves the block view from file (template).
Assume you know templates are using block functions and blocks extends core classes ( Template.php or AbstractBlock.php not in all cases ).
The data is populating by using toHtml()
Hope this helps.
Answered by Krishna ijjada on December 24, 2020
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP