1

What I thought to be an easy update, well at least in Magento 1, has turned into a huge adventure. Simply updating a template and a block type for a single category via the Magento admin, an out of box feature for Magento 1... Now I'm stumped. :(

Originally I tried the below: Note: I used the blocktype of Magento\Catalog\Block\Navigation as it contained access to the current categories children and other logic I needed, why duplicate something that already exists right? In the admin panel I am editing a category and have set the "Custom Layout Update" to:

<referenceBlock name="category.products.list">
    <arguments>
        <argument name="template" xsi:type="string">Magento_Catalog::product/subcat-list.phtml</argument>
    </arguments>
    <block class="Magento\Catalog\Block\Navigation"/>
</referenceBlock>

Then I got the error: Please correct the XML data and try again. Element 'referenceBlock': This element is not expected. Expected is one of ( referenceContainer, container, update, move ). Line: 1

Why do you need to target a reference container inside of the Admin panel, and can't just reference the desired block? In my adventures, I believe I tried this exact xml inside module layout file and I remember it working as expected.

Common Magento, How do you reference a block nested two levels deep from the container without duplicating everything?

Let's start being crazy, begin by using methods that are supposedly deprecated by Magento. I then tried the following with visual success... Feels so dirty:

<referenceContainer name="content">
    <referenceBlock name="category.products">
        <block name="product_list" class="Magento\Catalog\Block\Navigation">
            <action method="setTemplate">
                <argument name="template" xsi:type="string">Magento_Catalog::product/subcat-list.phtml</argument>
            </action>
        </block>
    </referenceBlock>
</referenceContainer>

Well, this worked but now I get an exception in the logs of: Magento\Framework\Exception\LocalizedException: The element 'category.products' already has a child with alias 'product_list' in /var/www/signatureneedle_magento/html/vendor/magento/framework/Data/Structure.php:611

I know, because I'm redeclaring it Magento.... Can anyone tell me what I'm doing wrong? Am I crazy, or does this ability not exist anymore... or am I doing this completely wrong? Any help would be greatly appreciated.

Thank you,

Robert

Your Answer

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

Browse other questions tagged or ask your own question.