2

I have an issue with the new Magento layout update xml feature. I added a custom layout update file to change a category. It shows up in the Magento backend, but when I select it, nothing changes on the frontend. Anyone that may know the solution?

I'm aware of the issue with porto theme & the new layout update feature, but that issue is already solved. It's just that the xml changes don't appear on the frontend.

The layout file content:

app/design/frontend/Smartwave/porto_child/Magento_Catalog/layout/catalog_category_view_selectable_9_TEST.xml

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <update handle="catalog_category_view_selectable_9_TEST"/>
    <body>
        <css src="css/test.css" />
    </body>
</page> 

The category config:

enter image description here

5
  • You want to add CSS using custom layout update ?
    – Pawan
    Sep 28, 2020 at 15:46
  • That's just for test purpose. CSS files are easy to check if it works.
    – MartinE
    Sep 29, 2020 at 8:49
  • you need to use <head> tag instead of <body> for adding css
    – Pawan
    Sep 29, 2020 at 10:03
  • You can also add <referenceBlock name="page.main.title" remove="true"/> in body tag and see if it removes page title.
    – Pawan
    Sep 29, 2020 at 10:07
  • both dont work. <head> instead of <body> doesnt work. Also tried your suggestion with the page.main.title, but also doesnt work unfortunately
    – MartinE
    Sep 30, 2020 at 12:32

3 Answers 3

0

Did you find a solution for this? I am using Porto with Magento 2.4.2 and can't get the Custom Layout Update to have any effect on the frontend either...

What do you mean by "I'm aware of the issue with Porto theme & the new layout update feature, but that issue is already solved."?

Are you referencing the backend Custom Layout Update drop down display issue? I tried the solution suggested here: How to add/update custom layout update on magento 2.3.4 and it seemed to fix that part of the issue, but I still can't get the Custom Layout Update to have any effect on the frontend.

Trying to add a category page specific css file just like you....and I am stuck!

Any info you can share would be greatly appreciated! Thank you!

1
  • Hi @MartinE, Thank you very much - I was just explaining the issue to the Porto developer... I will give pass this suggestion along to them. Thank you much appreciated!
    – Chris
    Mar 26, 2021 at 13:57
0

Eventually, we found a solution. The reason this doesn't work, is because of the Porto theme.

We edited 2 files:

app/code/Smartwave/Megamenu/Model/Category/DataProvider.php

Added 'custom_layout_update_file' to design block below 'custom_layout_update'

app/code/Smartwave/Porto/etc/di.xml

Removed <preference for="Magento\Catalog\Controller\Category\View" type="Smartwave\Porto\Controller\Category\View" />

Re-deployed everything after these changes, and it worked perfectly.

0

I am working on 2.4.3 magento and the latest version of Porto.

Following up on MartinE's answer. I am trying to add a custom layout update to a product page and worked out this solution.

In the app/code/Smartwave/Porto/etc/di.xml I see the following line at line 29.

Comparing Smartwave\Porto\Helper\Product\View.php to vendor\magento\module-catalog\Helper\Product.php :

In vendor\magento\module-catalog\Helper\Product.php this line of code is on lines 217-219:

if ($settings->getPageLayoutHandles()) {
$resultPage->addPageLayoutHandles($settings->getPageLayoutHandles()); }

I added the above code into Smartwave\Porto\Helper\Product\View.php on lines 169 to 171.

And then ran:

php bin/magento setup:upgrade
php bin/magento setup:di:compile
php bin/magento setup:static-content:deploy  -f
php bin/magento cache:clean && php bin/magento cache:flush

And my custom layout is now overwriting my porto layout.

Thanks so much MartinE and hope this helps someone!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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