Magento 2 Difference between default.xml and default_head_blocks.xml
In Magento 2 Theme , default.xml
and default_head_blocks.xml
files are located in appdesignfrontend{package}{theme}Magento_Themelayout
can anyone tell me what is the difference between these two files ?
magento2
bumped to the homepage by Community♦ 3 mins ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
add a comment |
In Magento 2 Theme , default.xml
and default_head_blocks.xml
files are located in appdesignfrontend{package}{theme}Magento_Themelayout
can anyone tell me what is the difference between these two files ?
magento2
bumped to the homepage by Community♦ 3 mins ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
add a comment |
In Magento 2 Theme , default.xml
and default_head_blocks.xml
files are located in appdesignfrontend{package}{theme}Magento_Themelayout
can anyone tell me what is the difference between these two files ?
magento2
In Magento 2 Theme , default.xml
and default_head_blocks.xml
files are located in appdesignfrontend{package}{theme}Magento_Themelayout
can anyone tell me what is the difference between these two files ?
magento2
magento2
edited Sep 13 '18 at 9:42
Manashvi Birla
6,40751841
6,40751841
asked Sep 13 '18 at 9:33
Sanjay ShiyalSanjay Shiyal
412
412
bumped to the homepage by Community♦ 3 mins ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
bumped to the homepage by Community♦ 3 mins ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
The basic view of all Magento storefront pages in defined in two page configuration layout files located in the Magento_Theme module:
1) <Magento_Theme_module_dir>/view/frontend/layout/default.xml
: defines the page layout.
2) <Magento_Theme_module_dir>/view/frontend/layout/default_head_blocks.xml
: defines the scripts, images, and meta data included in pages’ <head>
section.
These basic page configuration layouts are extended in other Magento modules and in Magento themes.
You can also extend or override these files in your custom theme.
REF https://devdocs.magento.com/guides/v2.0/frontend-dev-guide/layouts/layout-overview.html
Thanks for you answer,but we can also define head section in default.xml so why concept of default_head_blocks.xml has come
– Sanjay Shiyal
Sep 13 '18 at 9:47
add a comment |
default_head_blocks.xml
is a specific layout of head section, and this file is called in default.xml
: <update handle="default_head_blocks"/>
so if you want to add in head section css
, javascript
, static assets
, The recommended way is to add them in default_head_blocks.xml
.
You can very well add them in default.xml
one and it works, but your code you will not be pretty as Magento do, Since we use Magento, we should apply the recommended way.
JavaScript, CSS and other static assets are added in the
section of a page configuration file. The default look of a Magento
store page is defined by
app/code/Magento/Theme/view/frontend/layout/default_head_blocks.xml.
The recommended way to add CSS and JavaScript is to extend this file
in your custom theme, and add the assets there.
add a comment |
default.xml: defines the page layout.
default_head_blocks.xml: defines the scripts, images, and meta data
included in pages’ section.
You can read more deep on it from magento doc enter link description here
Example of default_head_blocks.html
app/design/frontend/Vendor/theme/Magento_Theme/layout/default_head_blocks.xml
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<head>
<!-- Add local resources -->
<css src="css/my-styles.css"/>
<!-- The following two ways to add local JavaScript files are equal -->
<script src="Magento_Catalog::js/sample1.js"/>
<link src="js/sample.js"/>
<!-- Add external resources -->
<css src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap-theme.min.css" src_type="url" />
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js" src_type="url" />
<link rel="stylesheet" type="text/css" src="http://fonts.googleapis.com/css?family=Montserrat" src_type="url" />
</head>
</page>
Example of default.xml
app/code/Magento/Catalog/view/frontend/layout/default.xml
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
...
<referenceContainer name="sidebar.additional">
<block class="MagentoCatalogBlockProductCompareSidebar" name="catalog.compare.sidebar" template="product/compare/sidebar.phtml"/>
</referenceContainer>
...
</body>
</page>
Thanks for replay but we can also use head section in default.xml also so why default_head_blocks.xml concept has come.
– Sanjay Shiyal
Sep 13 '18 at 9:52
When you will add js and css using default_head_blocks.xm it will be add for all pages and in default.xml with in every module head will be for that module specific
– Ansar Husain
Sep 13 '18 at 9:54
like as some thing you want to add in head for catalog section only then you will use default.xml inside Magento_Catalog.
– Ansar Husain
Sep 13 '18 at 9:56
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "479"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f242081%2fmagento-2-difference-between-default-xml-and-default-head-blocks-xml%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
The basic view of all Magento storefront pages in defined in two page configuration layout files located in the Magento_Theme module:
1) <Magento_Theme_module_dir>/view/frontend/layout/default.xml
: defines the page layout.
2) <Magento_Theme_module_dir>/view/frontend/layout/default_head_blocks.xml
: defines the scripts, images, and meta data included in pages’ <head>
section.
These basic page configuration layouts are extended in other Magento modules and in Magento themes.
You can also extend or override these files in your custom theme.
REF https://devdocs.magento.com/guides/v2.0/frontend-dev-guide/layouts/layout-overview.html
Thanks for you answer,but we can also define head section in default.xml so why concept of default_head_blocks.xml has come
– Sanjay Shiyal
Sep 13 '18 at 9:47
add a comment |
The basic view of all Magento storefront pages in defined in two page configuration layout files located in the Magento_Theme module:
1) <Magento_Theme_module_dir>/view/frontend/layout/default.xml
: defines the page layout.
2) <Magento_Theme_module_dir>/view/frontend/layout/default_head_blocks.xml
: defines the scripts, images, and meta data included in pages’ <head>
section.
These basic page configuration layouts are extended in other Magento modules and in Magento themes.
You can also extend or override these files in your custom theme.
REF https://devdocs.magento.com/guides/v2.0/frontend-dev-guide/layouts/layout-overview.html
Thanks for you answer,but we can also define head section in default.xml so why concept of default_head_blocks.xml has come
– Sanjay Shiyal
Sep 13 '18 at 9:47
add a comment |
The basic view of all Magento storefront pages in defined in two page configuration layout files located in the Magento_Theme module:
1) <Magento_Theme_module_dir>/view/frontend/layout/default.xml
: defines the page layout.
2) <Magento_Theme_module_dir>/view/frontend/layout/default_head_blocks.xml
: defines the scripts, images, and meta data included in pages’ <head>
section.
These basic page configuration layouts are extended in other Magento modules and in Magento themes.
You can also extend or override these files in your custom theme.
REF https://devdocs.magento.com/guides/v2.0/frontend-dev-guide/layouts/layout-overview.html
The basic view of all Magento storefront pages in defined in two page configuration layout files located in the Magento_Theme module:
1) <Magento_Theme_module_dir>/view/frontend/layout/default.xml
: defines the page layout.
2) <Magento_Theme_module_dir>/view/frontend/layout/default_head_blocks.xml
: defines the scripts, images, and meta data included in pages’ <head>
section.
These basic page configuration layouts are extended in other Magento modules and in Magento themes.
You can also extend or override these files in your custom theme.
REF https://devdocs.magento.com/guides/v2.0/frontend-dev-guide/layouts/layout-overview.html
answered Sep 13 '18 at 9:44
Manashvi BirlaManashvi Birla
6,40751841
6,40751841
Thanks for you answer,but we can also define head section in default.xml so why concept of default_head_blocks.xml has come
– Sanjay Shiyal
Sep 13 '18 at 9:47
add a comment |
Thanks for you answer,but we can also define head section in default.xml so why concept of default_head_blocks.xml has come
– Sanjay Shiyal
Sep 13 '18 at 9:47
Thanks for you answer,but we can also define head section in default.xml so why concept of default_head_blocks.xml has come
– Sanjay Shiyal
Sep 13 '18 at 9:47
Thanks for you answer,but we can also define head section in default.xml so why concept of default_head_blocks.xml has come
– Sanjay Shiyal
Sep 13 '18 at 9:47
add a comment |
default_head_blocks.xml
is a specific layout of head section, and this file is called in default.xml
: <update handle="default_head_blocks"/>
so if you want to add in head section css
, javascript
, static assets
, The recommended way is to add them in default_head_blocks.xml
.
You can very well add them in default.xml
one and it works, but your code you will not be pretty as Magento do, Since we use Magento, we should apply the recommended way.
JavaScript, CSS and other static assets are added in the
section of a page configuration file. The default look of a Magento
store page is defined by
app/code/Magento/Theme/view/frontend/layout/default_head_blocks.xml.
The recommended way to add CSS and JavaScript is to extend this file
in your custom theme, and add the assets there.
add a comment |
default_head_blocks.xml
is a specific layout of head section, and this file is called in default.xml
: <update handle="default_head_blocks"/>
so if you want to add in head section css
, javascript
, static assets
, The recommended way is to add them in default_head_blocks.xml
.
You can very well add them in default.xml
one and it works, but your code you will not be pretty as Magento do, Since we use Magento, we should apply the recommended way.
JavaScript, CSS and other static assets are added in the
section of a page configuration file. The default look of a Magento
store page is defined by
app/code/Magento/Theme/view/frontend/layout/default_head_blocks.xml.
The recommended way to add CSS and JavaScript is to extend this file
in your custom theme, and add the assets there.
add a comment |
default_head_blocks.xml
is a specific layout of head section, and this file is called in default.xml
: <update handle="default_head_blocks"/>
so if you want to add in head section css
, javascript
, static assets
, The recommended way is to add them in default_head_blocks.xml
.
You can very well add them in default.xml
one and it works, but your code you will not be pretty as Magento do, Since we use Magento, we should apply the recommended way.
JavaScript, CSS and other static assets are added in the
section of a page configuration file. The default look of a Magento
store page is defined by
app/code/Magento/Theme/view/frontend/layout/default_head_blocks.xml.
The recommended way to add CSS and JavaScript is to extend this file
in your custom theme, and add the assets there.
default_head_blocks.xml
is a specific layout of head section, and this file is called in default.xml
: <update handle="default_head_blocks"/>
so if you want to add in head section css
, javascript
, static assets
, The recommended way is to add them in default_head_blocks.xml
.
You can very well add them in default.xml
one and it works, but your code you will not be pretty as Magento do, Since we use Magento, we should apply the recommended way.
JavaScript, CSS and other static assets are added in the
section of a page configuration file. The default look of a Magento
store page is defined by
app/code/Magento/Theme/view/frontend/layout/default_head_blocks.xml.
The recommended way to add CSS and JavaScript is to extend this file
in your custom theme, and add the assets there.
answered Sep 13 '18 at 10:04
PЯINCƏPЯINCƏ
8,33131143
8,33131143
add a comment |
add a comment |
default.xml: defines the page layout.
default_head_blocks.xml: defines the scripts, images, and meta data
included in pages’ section.
You can read more deep on it from magento doc enter link description here
Example of default_head_blocks.html
app/design/frontend/Vendor/theme/Magento_Theme/layout/default_head_blocks.xml
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<head>
<!-- Add local resources -->
<css src="css/my-styles.css"/>
<!-- The following two ways to add local JavaScript files are equal -->
<script src="Magento_Catalog::js/sample1.js"/>
<link src="js/sample.js"/>
<!-- Add external resources -->
<css src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap-theme.min.css" src_type="url" />
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js" src_type="url" />
<link rel="stylesheet" type="text/css" src="http://fonts.googleapis.com/css?family=Montserrat" src_type="url" />
</head>
</page>
Example of default.xml
app/code/Magento/Catalog/view/frontend/layout/default.xml
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
...
<referenceContainer name="sidebar.additional">
<block class="MagentoCatalogBlockProductCompareSidebar" name="catalog.compare.sidebar" template="product/compare/sidebar.phtml"/>
</referenceContainer>
...
</body>
</page>
Thanks for replay but we can also use head section in default.xml also so why default_head_blocks.xml concept has come.
– Sanjay Shiyal
Sep 13 '18 at 9:52
When you will add js and css using default_head_blocks.xm it will be add for all pages and in default.xml with in every module head will be for that module specific
– Ansar Husain
Sep 13 '18 at 9:54
like as some thing you want to add in head for catalog section only then you will use default.xml inside Magento_Catalog.
– Ansar Husain
Sep 13 '18 at 9:56
add a comment |
default.xml: defines the page layout.
default_head_blocks.xml: defines the scripts, images, and meta data
included in pages’ section.
You can read more deep on it from magento doc enter link description here
Example of default_head_blocks.html
app/design/frontend/Vendor/theme/Magento_Theme/layout/default_head_blocks.xml
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<head>
<!-- Add local resources -->
<css src="css/my-styles.css"/>
<!-- The following two ways to add local JavaScript files are equal -->
<script src="Magento_Catalog::js/sample1.js"/>
<link src="js/sample.js"/>
<!-- Add external resources -->
<css src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap-theme.min.css" src_type="url" />
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js" src_type="url" />
<link rel="stylesheet" type="text/css" src="http://fonts.googleapis.com/css?family=Montserrat" src_type="url" />
</head>
</page>
Example of default.xml
app/code/Magento/Catalog/view/frontend/layout/default.xml
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
...
<referenceContainer name="sidebar.additional">
<block class="MagentoCatalogBlockProductCompareSidebar" name="catalog.compare.sidebar" template="product/compare/sidebar.phtml"/>
</referenceContainer>
...
</body>
</page>
Thanks for replay but we can also use head section in default.xml also so why default_head_blocks.xml concept has come.
– Sanjay Shiyal
Sep 13 '18 at 9:52
When you will add js and css using default_head_blocks.xm it will be add for all pages and in default.xml with in every module head will be for that module specific
– Ansar Husain
Sep 13 '18 at 9:54
like as some thing you want to add in head for catalog section only then you will use default.xml inside Magento_Catalog.
– Ansar Husain
Sep 13 '18 at 9:56
add a comment |
default.xml: defines the page layout.
default_head_blocks.xml: defines the scripts, images, and meta data
included in pages’ section.
You can read more deep on it from magento doc enter link description here
Example of default_head_blocks.html
app/design/frontend/Vendor/theme/Magento_Theme/layout/default_head_blocks.xml
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<head>
<!-- Add local resources -->
<css src="css/my-styles.css"/>
<!-- The following two ways to add local JavaScript files are equal -->
<script src="Magento_Catalog::js/sample1.js"/>
<link src="js/sample.js"/>
<!-- Add external resources -->
<css src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap-theme.min.css" src_type="url" />
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js" src_type="url" />
<link rel="stylesheet" type="text/css" src="http://fonts.googleapis.com/css?family=Montserrat" src_type="url" />
</head>
</page>
Example of default.xml
app/code/Magento/Catalog/view/frontend/layout/default.xml
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
...
<referenceContainer name="sidebar.additional">
<block class="MagentoCatalogBlockProductCompareSidebar" name="catalog.compare.sidebar" template="product/compare/sidebar.phtml"/>
</referenceContainer>
...
</body>
</page>
default.xml: defines the page layout.
default_head_blocks.xml: defines the scripts, images, and meta data
included in pages’ section.
You can read more deep on it from magento doc enter link description here
Example of default_head_blocks.html
app/design/frontend/Vendor/theme/Magento_Theme/layout/default_head_blocks.xml
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<head>
<!-- Add local resources -->
<css src="css/my-styles.css"/>
<!-- The following two ways to add local JavaScript files are equal -->
<script src="Magento_Catalog::js/sample1.js"/>
<link src="js/sample.js"/>
<!-- Add external resources -->
<css src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap-theme.min.css" src_type="url" />
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js" src_type="url" />
<link rel="stylesheet" type="text/css" src="http://fonts.googleapis.com/css?family=Montserrat" src_type="url" />
</head>
</page>
Example of default.xml
app/code/Magento/Catalog/view/frontend/layout/default.xml
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
...
<referenceContainer name="sidebar.additional">
<block class="MagentoCatalogBlockProductCompareSidebar" name="catalog.compare.sidebar" template="product/compare/sidebar.phtml"/>
</referenceContainer>
...
</body>
</page>
edited Sep 13 '18 at 10:06
answered Sep 13 '18 at 9:44
Ansar HusainAnsar Husain
1,707218
1,707218
Thanks for replay but we can also use head section in default.xml also so why default_head_blocks.xml concept has come.
– Sanjay Shiyal
Sep 13 '18 at 9:52
When you will add js and css using default_head_blocks.xm it will be add for all pages and in default.xml with in every module head will be for that module specific
– Ansar Husain
Sep 13 '18 at 9:54
like as some thing you want to add in head for catalog section only then you will use default.xml inside Magento_Catalog.
– Ansar Husain
Sep 13 '18 at 9:56
add a comment |
Thanks for replay but we can also use head section in default.xml also so why default_head_blocks.xml concept has come.
– Sanjay Shiyal
Sep 13 '18 at 9:52
When you will add js and css using default_head_blocks.xm it will be add for all pages and in default.xml with in every module head will be for that module specific
– Ansar Husain
Sep 13 '18 at 9:54
like as some thing you want to add in head for catalog section only then you will use default.xml inside Magento_Catalog.
– Ansar Husain
Sep 13 '18 at 9:56
Thanks for replay but we can also use head section in default.xml also so why default_head_blocks.xml concept has come.
– Sanjay Shiyal
Sep 13 '18 at 9:52
Thanks for replay but we can also use head section in default.xml also so why default_head_blocks.xml concept has come.
– Sanjay Shiyal
Sep 13 '18 at 9:52
When you will add js and css using default_head_blocks.xm it will be add for all pages and in default.xml with in every module head will be for that module specific
– Ansar Husain
Sep 13 '18 at 9:54
When you will add js and css using default_head_blocks.xm it will be add for all pages and in default.xml with in every module head will be for that module specific
– Ansar Husain
Sep 13 '18 at 9:54
like as some thing you want to add in head for catalog section only then you will use default.xml inside Magento_Catalog.
– Ansar Husain
Sep 13 '18 at 9:56
like as some thing you want to add in head for catalog section only then you will use default.xml inside Magento_Catalog.
– Ansar Husain
Sep 13 '18 at 9:56
add a comment |
Thanks for contributing an answer to Magento Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f242081%2fmagento-2-difference-between-default-xml-and-default-head-blocks-xml%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown