I'm going completely mad here. I have the following in "Layout Update XML" in one of my categories:
<referenceContainer name="content">
<block class="Us\Tastemakers\Block\Tastemakers" name="category.tastemakers" template="Us_Tastemakers::tastemakers.phtml" before="-"/>
</referenceContainer>
I then have the following files:
app/code/Us/Tastemakers/Block
:
<?php
namespace Us\Tastemakers\Block;
class Tastemakers extends \Magento\Framework\View\Element\Template
{
protected $_productCollectionFactory;
public function __construct(
\Magento\Backend\Block\Template\Context $context,
\Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $productCollectionFactory,
array $data = []
)
{
$this->_productCollectionFactory = $productCollectionFactory;
parent::__construct($context, $data);
}
public function getProductCollection()
{
$collection = $this->_productCollectionFactory->create();
$collection->addAttributeToSelect('*');
$collection->setPageSize(3); // fetching only 3 products
return $collection;
}
}
And app/code/Us/Tastemakers/view/frontend/templates/tastemakers.phtml
<?php
/* *
* @var \Us\Tastemakers\Block\Tastemakers $block
*/
echo 'Hi there. I\'m here. I\'m a tastemaker';
// $productCollection = $block->getProductCollection();
// foreach ($productCollection as $product) {
// echo "Inside view <pre>";
// print_r($product->getData());
// echo "</pre><br>";
// }
But none of my text gets displayed anywhere. I have done a complete cache:flush
for good measure.
I'm completely going mad here. I must be missing something. Please put me out of my misery!
Update
I have the impression that something is stopping the admin's layout update xml from doing anything at all:
I have now added the same XML block to the catalog_category_view.xml
and it works fine.
However, no layout update xml in the admin backend have any effect.
Here are two I have tried:
<referenceContainer name="content">
<referenceBlock name="category.tastemakers">
<arguments>
<argument name="skus" xsi:type="string">1,2,3</argument>
</arguments>
</referenceBlock>
</referenceContainer>
<referenceContainer name="content">
<referenceBlock name="category.tastemakers" remove="true"/>
</referenceContainer>
It literally doesn't do anything.