2

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.

Amit Bera
77.8k21 gold badges127 silver badges240 bronze badges
asked Apr 6, 2017 at 9:12
1

4 Answers 4

9

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

answered Apr 6, 2017 at 12:01
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

Amit Bera
77.8k21 gold badges127 silver badges240 bronze badges
answered Apr 6, 2017 at 9:19
9
  • +1 from me, but if I am not using any theme, I am using default magento 2 theme, then what should be strutcture Commented Apr 6, 2017 at 9:21
  • /app/design/frontend/Magento/default/Magento_Theme/templates/html/sections.phtml Try this ;) Commented Apr 6, 2017 at 9:22
  • okay.. let me check that Commented Apr 6, 2017 at 9:22
  • no still not working Commented Apr 6, 2017 at 9:23
  • are You using luma theme ? /app/design/frontend/Magento/luma/Magento_Theme/templates‌​/html/sections.phtml Commented Apr 6, 2017 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>
answered Mar 12, 2018 at 9:35
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

answered Mar 12, 2018 at 10:07

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.