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.
-
you have to just create theme in your project and after setup theme you can override directly same as above. you can refer from magento.stackexchange.com/questions/136289/…Rakesh Jesadiya– Rakesh Jesadiya2017年04月06日 12:14:51 +00:00Commented Apr 6, 2017 at 12:14
4 Answers 4
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
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 strutctureMrunmay Deswandikar– Mrunmay Deswandikar2017年04月06日 09:21:05 +00:00Commented Apr 6, 2017 at 9:21
-
/app/design/frontend/Magento/default/Magento_Theme/templates/html/sections.phtml Try this ;)Martins– Martins2017年04月06日 09:22:09 +00:00Commented Apr 6, 2017 at 9:22
-
okay.. let me check thatMrunmay Deswandikar– Mrunmay Deswandikar2017年04月06日 09:22:26 +00:00Commented Apr 6, 2017 at 9:22
-
no still not workingMrunmay Deswandikar– Mrunmay Deswandikar2017年04月06日 09:23:30 +00:00Commented Apr 6, 2017 at 9:23
-
are You using luma theme ? /app/design/frontend/Magento/luma/Magento_Theme/templates/html/sections.phtmlMartins– Martins2017年04月06日 09:25:49 +00:00Commented Apr 6, 2017 at 9:25
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>
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