0

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.

0

Remove the before="-" and see if it works.

Or check on the web page source in case it's putting the text somewhere on the page.

  • Thanks for taking the time to answer @kibret. It seems to me to be a more general problem with the Admin's Update Layout XML: I have since added this to the layout's XML files, and it works fine. It does however appear that none of the changes I attempt to make through the admin's update layout xml have any effect whatsoever. Have a look at my edit above. – nanos Sep 11 at 10:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.