1

I want to override sections.phtml file from vendor/magento/module-theme/view/templates/html/

I am using default magento theme

I have created structure,

app/design/frontend/Magento/Magento-Theme/templates/html/sections.phtml

But it is not running, the default one is getting loaded.

7

You can achieve this two ways, choose either one as per your requirements [from module or theme]

From Theme

Create one custom theme after that you need to create the below file for override sections.phtml

app/design/frontend/YourVendorName/YourThemeName/Magento-Theme/templates/html/sections.phtml

From Module

Create custom module after that create below default.xml file to overwrite sections.phtml

app/code/YourVendorName/YourModuleName/view/frontend/layout/default.xml

    <?xml version="1.0"?>
    <!--
    /**
     * Copyright © 2013-2017 Magento, Inc. All rights reserved.
     * See COPYING.txt for license details.
     */
    -->
    <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
        <body>
            <referenceBlock name="navigation.sections">
                <action method="setTemplate">
                    <argument name="template" xsi:type="string">YourVendorName_YourModuleName::sections.phtml</argument>
                </action>
            </referenceBlock>
        </body>
    </page>     

place the sections.phtml in below path

app/code/YourVendorName/YourModuleName/view/frontend/templates/sections.phtml

2

You can do it if You create Your new theme and inherit from base

http://devdocs.magento.com/guides/v2.1/frontend-dev-guide/themes/theme-create.html

copy from here

vendor/magento/module-theme/view/templates/html/sections.phtml

add in your theme /app/design/frontend/Vendor/default/Magento_Theme/templates/html/sections.phtml

  • +1 from me, but if I am not using any theme, I am using default magento 2 theme, then what should be strutcture – Mrunmay Deswandikar Apr 6 '17 at 9:21
  • /app/design/frontend/Magento/default/Magento_Theme/templates/html/sections.phtml Try this ;) – Martins Apr 6 '17 at 9:22
  • okay.. let me check that – Mrunmay Deswandikar Apr 6 '17 at 9:22
  • no still not working – Mrunmay Deswandikar Apr 6 '17 at 9:23
  • are You using luma theme ? /app/design/frontend/Magento/luma/Magento_Theme/templates‌​/html/sections.phtml – Martins Apr 6 '17 at 9:25
0

After banging my head for half an hour on this...

The documentation suggests that the templates location should be:

<theme_dir>/<Namespace>_<Module>/templates/<path_to_templates>

The template we are after being in vendor/magento/module-theme/view/templates/html/ you would think that the path should be

<theme_dir>/magento_module-theme/templates/<path_to_templates>

which would correspond to <Namespace> underscore <Module> as per the folder structure, but that's not what the documentation means.

Open the module registration.php and see how it is registered: Magento_Theme so namespace here is Magento and module name is Theme and that's it.

So in the end your path will be:

<theme_dir>/Magento_Theme/templates/<path_to_templates>
0

You have the wrong path in the structure you have to use a theme from default magento like Magento_Blank or create a new theme that has inheritance from a magento theme ( check devdocs on how to create new theme ) and your file has to be in the following structure design/frontend/[Your_Package]/[Your_theme]/Magento_Theme/templates/html/sections.phtml

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.