Magento2: How to add different custom css file on specific CMS pages
I tried so may things but unable to add the CSS & JS files for each Static CMS pages.
I know if CSS can be added in cms_page_view.xml
but this will reflect in all pages.
is there anyway to add different CSS files for different static pages.
magento2 magento-2.1 magento-2.0.2 cms-pages
add a comment |
I tried so may things but unable to add the CSS & JS files for each Static CMS pages.
I know if CSS can be added in cms_page_view.xml
but this will reflect in all pages.
is there anyway to add different CSS files for different static pages.
magento2 magento-2.1 magento-2.0.2 cms-pages
add a comment |
I tried so may things but unable to add the CSS & JS files for each Static CMS pages.
I know if CSS can be added in cms_page_view.xml
but this will reflect in all pages.
is there anyway to add different CSS files for different static pages.
magento2 magento-2.1 magento-2.0.2 cms-pages
I tried so may things but unable to add the CSS & JS files for each Static CMS pages.
I know if CSS can be added in cms_page_view.xml
but this will reflect in all pages.
is there anyway to add different CSS files for different static pages.
magento2 magento-2.1 magento-2.0.2 cms-pages
magento2 magento-2.1 magento-2.0.2 cms-pages
edited Jul 20 '16 at 14:41
Klettseb
3,05031751
3,05031751
asked Jul 20 '16 at 14:34
Mohammad MujassamMohammad Mujassam
1,1471227
1,1471227
add a comment |
add a comment |
4 Answers
4
active
oldest
votes
You can add Layout Update XML update
GOTO ADMIN -> Content -> Pages -> Edit page -> Design -> Layout Update XML
With the content :
<head>
<css src="Namespace_YourModule::css/styles.css"/>
</head>
Then there is a bug in Magento 2, you need to override the default Magento 2 vendor/magento/framework/View/Layout/etc/page_layout.xsd
validation file.
A workaround, not a clean solution, but waiting Magento 2 to allow override xsd files
app/code/Vendor/Module/etc/di.xml
<preference for="MagentoFrameworkViewModelLayoutUpdateValidator" type="VendorModuleModelLayoutUpdateValidator" />
app/code/Vendor/Module/etc/page_layout.xsd
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:include schemaLocation="urn:magento:framework:View/Layout/etc/elements.xsd"/>
<xs:include schemaLocation="urn:magento:framework:View/Layout/etc/head.xsd"/>
<xs:include schemaLocation="urn:magento:framework:View/Layout/etc/body.xsd"/>
<xs:complexType name="pageLayoutType">
<xs:sequence minOccurs="0" maxOccurs="unbounded">
<xs:element ref="referenceContainer" minOccurs="0" maxOccurs="unbounded"/>
<xs:element ref="container" minOccurs="0" maxOccurs="unbounded"/>
<xs:element ref="update" minOccurs="0" maxOccurs="unbounded"/>
<xs:element ref="move" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="head" type="headType" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="body" type="bodyType" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
<xs:element name="layout" type="pageLayoutType">
<xs:unique name="containerKey">
<xs:selector xpath=".//container"/>
<xs:field xpath="@name"/>
</xs:unique>
</xs:element>
</xs:schema>
app/code/Vendor/Module/Model/Layout/Update/Validator.php
<?php
namespace HublotSetupModelLayoutUpdate;
use MagentoFrameworkConfigDomUrnResolver;
class Validator extends MagentoFrameworkViewModelLayoutUpdateValidator
{
const LAYOUT_SCHEMA_PAGE_HANDLE = 'page_layout';
const LAYOUT_SCHEMA_MERGED = 'layout_merged';
/**
* @param MagentoFrameworkConfigDomFactory $domConfigFactory
* @param MagentoFrameworkConfigDomUrnResolver $urnResolver
*/
public function __construct(
MagentoFrameworkConfigDomFactory $domConfigFactory,
UrnResolver $urnResolver
) {
$this->_domConfigFactory = $domConfigFactory;
$this->_initMessageTemplates();
$this->_xsdSchemas = [
self::LAYOUT_SCHEMA_PAGE_HANDLE => $urnResolver->getRealPath(
'urn:hublot:module:Hublot_Setup:etc/page_layout.xsd'
),
self::LAYOUT_SCHEMA_MERGED => $urnResolver->getRealPath(
'urn:magento:framework:View/Layout/etc/layout_merged.xsd'
),
];
}
}
For reference to see when this is eventually fixed, this is the Magento bug in question: github.com/magento/magento2/issues/4454
– Scott Buchanan
Oct 5 '17 at 14:26
It is indeed a bug I have same issue 2.2.2 there is the fix :github.com/magento/magento2/commit/…
– Juliano Vargas
Apr 30 '18 at 10:39
add a comment |
You can add custom css like below:
make an entry in layout file
<page>
<head>
<css src="css/ie-9.css" ie_condition="IE 9" />
<css src="Magento_Catalog::css/custom.css" />
<css src="Custom_SampleModule::css/custom.css"/>
</head>
</page>
add a comment |
I found that Franck Garnier's does not quite work on 2.1.16.
I had to change the last file, Validator.php, a bit to get it to work as follows.
namespace VendorCmsLayoutFixModelLayoutUpdate;
use MagentoFrameworkAppObjectManager;
use MagentoFrameworkConfigDomUrnResolver;
use MagentoFrameworkConfigDomFactory;
use MagentoFrameworkConfigValidationStateInterface;
class Validator extends MagentoFrameworkViewModelLayoutUpdateValidator
{
const LAYOUT_SCHEMA_PAGE_HANDLE = 'page_layout';
const LAYOUT_SCHEMA_MERGED = 'layout_merged';
private $validationState;
public function __construct(
DomFactory $domConfigFactory,
UrnResolver $urnResolver,
ValidationStateInterface $validationState = null
) {
parent::__construct($domConfigFactory, $urnResolver);
$this->_xsdSchemas = [
self::LAYOUT_SCHEMA_PAGE_HANDLE => $urnResolver->getRealPath(
'urn:vendor:module:Vendor_CmsLayoutFix:etc/page_layout.xsd'
),
self::LAYOUT_SCHEMA_MERGED => $urnResolver->getRealPath(
'urn:magento:framework:View/Layout/etc/layout_merged.xsd'
),
];
}
}
WHERE:
vendor = Vendor
module = CmsLayoutFix
New contributor
add a comment |
In magento all CMS pages have an option of Layout Update XML update .Just Call your Custom code there also add CSS or JS .
Admin CMS Pages
GOTO ADMIN -> Content -> Pages -> Edit page -> Design -> Layout Update XML
add below call
<head>
<css src="Namespace_YourModule::css/styles.css"/>
</head>
this works in page layout configuration not in Layout Update XML , hope you checked...
– Mohammad Mujassam
Jul 21 '16 at 4:44
It is working fine I have tested this code . just remove "Namespace_YourModule::" and set in to "Layout Update XML" and refresh you Cache so you can show in that page only.
– Hitesh Vaghasiya
Jul 21 '16 at 18:59
1
Please correct the XML data and try again. Element 'head': This element is not expected. Expected is one of ( referenceContainer, container, update, move ). Line: 1
this we will get if we put anything else apart from above four Element. I am using magento 2.0.7
– Mohammad Mujassam
Jul 22 '16 at 4:40
1
Yeah, this worked for me. Just remember to flush the cache after you change the layout for the cms page to pickup the change.
– Dallas Clarke
Dec 13 '17 at 3:23
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%2f126646%2fmagento2-how-to-add-different-custom-css-file-on-specific-cms-pages%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can add Layout Update XML update
GOTO ADMIN -> Content -> Pages -> Edit page -> Design -> Layout Update XML
With the content :
<head>
<css src="Namespace_YourModule::css/styles.css"/>
</head>
Then there is a bug in Magento 2, you need to override the default Magento 2 vendor/magento/framework/View/Layout/etc/page_layout.xsd
validation file.
A workaround, not a clean solution, but waiting Magento 2 to allow override xsd files
app/code/Vendor/Module/etc/di.xml
<preference for="MagentoFrameworkViewModelLayoutUpdateValidator" type="VendorModuleModelLayoutUpdateValidator" />
app/code/Vendor/Module/etc/page_layout.xsd
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:include schemaLocation="urn:magento:framework:View/Layout/etc/elements.xsd"/>
<xs:include schemaLocation="urn:magento:framework:View/Layout/etc/head.xsd"/>
<xs:include schemaLocation="urn:magento:framework:View/Layout/etc/body.xsd"/>
<xs:complexType name="pageLayoutType">
<xs:sequence minOccurs="0" maxOccurs="unbounded">
<xs:element ref="referenceContainer" minOccurs="0" maxOccurs="unbounded"/>
<xs:element ref="container" minOccurs="0" maxOccurs="unbounded"/>
<xs:element ref="update" minOccurs="0" maxOccurs="unbounded"/>
<xs:element ref="move" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="head" type="headType" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="body" type="bodyType" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
<xs:element name="layout" type="pageLayoutType">
<xs:unique name="containerKey">
<xs:selector xpath=".//container"/>
<xs:field xpath="@name"/>
</xs:unique>
</xs:element>
</xs:schema>
app/code/Vendor/Module/Model/Layout/Update/Validator.php
<?php
namespace HublotSetupModelLayoutUpdate;
use MagentoFrameworkConfigDomUrnResolver;
class Validator extends MagentoFrameworkViewModelLayoutUpdateValidator
{
const LAYOUT_SCHEMA_PAGE_HANDLE = 'page_layout';
const LAYOUT_SCHEMA_MERGED = 'layout_merged';
/**
* @param MagentoFrameworkConfigDomFactory $domConfigFactory
* @param MagentoFrameworkConfigDomUrnResolver $urnResolver
*/
public function __construct(
MagentoFrameworkConfigDomFactory $domConfigFactory,
UrnResolver $urnResolver
) {
$this->_domConfigFactory = $domConfigFactory;
$this->_initMessageTemplates();
$this->_xsdSchemas = [
self::LAYOUT_SCHEMA_PAGE_HANDLE => $urnResolver->getRealPath(
'urn:hublot:module:Hublot_Setup:etc/page_layout.xsd'
),
self::LAYOUT_SCHEMA_MERGED => $urnResolver->getRealPath(
'urn:magento:framework:View/Layout/etc/layout_merged.xsd'
),
];
}
}
For reference to see when this is eventually fixed, this is the Magento bug in question: github.com/magento/magento2/issues/4454
– Scott Buchanan
Oct 5 '17 at 14:26
It is indeed a bug I have same issue 2.2.2 there is the fix :github.com/magento/magento2/commit/…
– Juliano Vargas
Apr 30 '18 at 10:39
add a comment |
You can add Layout Update XML update
GOTO ADMIN -> Content -> Pages -> Edit page -> Design -> Layout Update XML
With the content :
<head>
<css src="Namespace_YourModule::css/styles.css"/>
</head>
Then there is a bug in Magento 2, you need to override the default Magento 2 vendor/magento/framework/View/Layout/etc/page_layout.xsd
validation file.
A workaround, not a clean solution, but waiting Magento 2 to allow override xsd files
app/code/Vendor/Module/etc/di.xml
<preference for="MagentoFrameworkViewModelLayoutUpdateValidator" type="VendorModuleModelLayoutUpdateValidator" />
app/code/Vendor/Module/etc/page_layout.xsd
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:include schemaLocation="urn:magento:framework:View/Layout/etc/elements.xsd"/>
<xs:include schemaLocation="urn:magento:framework:View/Layout/etc/head.xsd"/>
<xs:include schemaLocation="urn:magento:framework:View/Layout/etc/body.xsd"/>
<xs:complexType name="pageLayoutType">
<xs:sequence minOccurs="0" maxOccurs="unbounded">
<xs:element ref="referenceContainer" minOccurs="0" maxOccurs="unbounded"/>
<xs:element ref="container" minOccurs="0" maxOccurs="unbounded"/>
<xs:element ref="update" minOccurs="0" maxOccurs="unbounded"/>
<xs:element ref="move" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="head" type="headType" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="body" type="bodyType" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
<xs:element name="layout" type="pageLayoutType">
<xs:unique name="containerKey">
<xs:selector xpath=".//container"/>
<xs:field xpath="@name"/>
</xs:unique>
</xs:element>
</xs:schema>
app/code/Vendor/Module/Model/Layout/Update/Validator.php
<?php
namespace HublotSetupModelLayoutUpdate;
use MagentoFrameworkConfigDomUrnResolver;
class Validator extends MagentoFrameworkViewModelLayoutUpdateValidator
{
const LAYOUT_SCHEMA_PAGE_HANDLE = 'page_layout';
const LAYOUT_SCHEMA_MERGED = 'layout_merged';
/**
* @param MagentoFrameworkConfigDomFactory $domConfigFactory
* @param MagentoFrameworkConfigDomUrnResolver $urnResolver
*/
public function __construct(
MagentoFrameworkConfigDomFactory $domConfigFactory,
UrnResolver $urnResolver
) {
$this->_domConfigFactory = $domConfigFactory;
$this->_initMessageTemplates();
$this->_xsdSchemas = [
self::LAYOUT_SCHEMA_PAGE_HANDLE => $urnResolver->getRealPath(
'urn:hublot:module:Hublot_Setup:etc/page_layout.xsd'
),
self::LAYOUT_SCHEMA_MERGED => $urnResolver->getRealPath(
'urn:magento:framework:View/Layout/etc/layout_merged.xsd'
),
];
}
}
For reference to see when this is eventually fixed, this is the Magento bug in question: github.com/magento/magento2/issues/4454
– Scott Buchanan
Oct 5 '17 at 14:26
It is indeed a bug I have same issue 2.2.2 there is the fix :github.com/magento/magento2/commit/…
– Juliano Vargas
Apr 30 '18 at 10:39
add a comment |
You can add Layout Update XML update
GOTO ADMIN -> Content -> Pages -> Edit page -> Design -> Layout Update XML
With the content :
<head>
<css src="Namespace_YourModule::css/styles.css"/>
</head>
Then there is a bug in Magento 2, you need to override the default Magento 2 vendor/magento/framework/View/Layout/etc/page_layout.xsd
validation file.
A workaround, not a clean solution, but waiting Magento 2 to allow override xsd files
app/code/Vendor/Module/etc/di.xml
<preference for="MagentoFrameworkViewModelLayoutUpdateValidator" type="VendorModuleModelLayoutUpdateValidator" />
app/code/Vendor/Module/etc/page_layout.xsd
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:include schemaLocation="urn:magento:framework:View/Layout/etc/elements.xsd"/>
<xs:include schemaLocation="urn:magento:framework:View/Layout/etc/head.xsd"/>
<xs:include schemaLocation="urn:magento:framework:View/Layout/etc/body.xsd"/>
<xs:complexType name="pageLayoutType">
<xs:sequence minOccurs="0" maxOccurs="unbounded">
<xs:element ref="referenceContainer" minOccurs="0" maxOccurs="unbounded"/>
<xs:element ref="container" minOccurs="0" maxOccurs="unbounded"/>
<xs:element ref="update" minOccurs="0" maxOccurs="unbounded"/>
<xs:element ref="move" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="head" type="headType" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="body" type="bodyType" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
<xs:element name="layout" type="pageLayoutType">
<xs:unique name="containerKey">
<xs:selector xpath=".//container"/>
<xs:field xpath="@name"/>
</xs:unique>
</xs:element>
</xs:schema>
app/code/Vendor/Module/Model/Layout/Update/Validator.php
<?php
namespace HublotSetupModelLayoutUpdate;
use MagentoFrameworkConfigDomUrnResolver;
class Validator extends MagentoFrameworkViewModelLayoutUpdateValidator
{
const LAYOUT_SCHEMA_PAGE_HANDLE = 'page_layout';
const LAYOUT_SCHEMA_MERGED = 'layout_merged';
/**
* @param MagentoFrameworkConfigDomFactory $domConfigFactory
* @param MagentoFrameworkConfigDomUrnResolver $urnResolver
*/
public function __construct(
MagentoFrameworkConfigDomFactory $domConfigFactory,
UrnResolver $urnResolver
) {
$this->_domConfigFactory = $domConfigFactory;
$this->_initMessageTemplates();
$this->_xsdSchemas = [
self::LAYOUT_SCHEMA_PAGE_HANDLE => $urnResolver->getRealPath(
'urn:hublot:module:Hublot_Setup:etc/page_layout.xsd'
),
self::LAYOUT_SCHEMA_MERGED => $urnResolver->getRealPath(
'urn:magento:framework:View/Layout/etc/layout_merged.xsd'
),
];
}
}
You can add Layout Update XML update
GOTO ADMIN -> Content -> Pages -> Edit page -> Design -> Layout Update XML
With the content :
<head>
<css src="Namespace_YourModule::css/styles.css"/>
</head>
Then there is a bug in Magento 2, you need to override the default Magento 2 vendor/magento/framework/View/Layout/etc/page_layout.xsd
validation file.
A workaround, not a clean solution, but waiting Magento 2 to allow override xsd files
app/code/Vendor/Module/etc/di.xml
<preference for="MagentoFrameworkViewModelLayoutUpdateValidator" type="VendorModuleModelLayoutUpdateValidator" />
app/code/Vendor/Module/etc/page_layout.xsd
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:include schemaLocation="urn:magento:framework:View/Layout/etc/elements.xsd"/>
<xs:include schemaLocation="urn:magento:framework:View/Layout/etc/head.xsd"/>
<xs:include schemaLocation="urn:magento:framework:View/Layout/etc/body.xsd"/>
<xs:complexType name="pageLayoutType">
<xs:sequence minOccurs="0" maxOccurs="unbounded">
<xs:element ref="referenceContainer" minOccurs="0" maxOccurs="unbounded"/>
<xs:element ref="container" minOccurs="0" maxOccurs="unbounded"/>
<xs:element ref="update" minOccurs="0" maxOccurs="unbounded"/>
<xs:element ref="move" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="head" type="headType" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="body" type="bodyType" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
<xs:element name="layout" type="pageLayoutType">
<xs:unique name="containerKey">
<xs:selector xpath=".//container"/>
<xs:field xpath="@name"/>
</xs:unique>
</xs:element>
</xs:schema>
app/code/Vendor/Module/Model/Layout/Update/Validator.php
<?php
namespace HublotSetupModelLayoutUpdate;
use MagentoFrameworkConfigDomUrnResolver;
class Validator extends MagentoFrameworkViewModelLayoutUpdateValidator
{
const LAYOUT_SCHEMA_PAGE_HANDLE = 'page_layout';
const LAYOUT_SCHEMA_MERGED = 'layout_merged';
/**
* @param MagentoFrameworkConfigDomFactory $domConfigFactory
* @param MagentoFrameworkConfigDomUrnResolver $urnResolver
*/
public function __construct(
MagentoFrameworkConfigDomFactory $domConfigFactory,
UrnResolver $urnResolver
) {
$this->_domConfigFactory = $domConfigFactory;
$this->_initMessageTemplates();
$this->_xsdSchemas = [
self::LAYOUT_SCHEMA_PAGE_HANDLE => $urnResolver->getRealPath(
'urn:hublot:module:Hublot_Setup:etc/page_layout.xsd'
),
self::LAYOUT_SCHEMA_MERGED => $urnResolver->getRealPath(
'urn:magento:framework:View/Layout/etc/layout_merged.xsd'
),
];
}
}
answered Mar 27 '17 at 10:23
Franck GarnierFranck Garnier
2,016826
2,016826
For reference to see when this is eventually fixed, this is the Magento bug in question: github.com/magento/magento2/issues/4454
– Scott Buchanan
Oct 5 '17 at 14:26
It is indeed a bug I have same issue 2.2.2 there is the fix :github.com/magento/magento2/commit/…
– Juliano Vargas
Apr 30 '18 at 10:39
add a comment |
For reference to see when this is eventually fixed, this is the Magento bug in question: github.com/magento/magento2/issues/4454
– Scott Buchanan
Oct 5 '17 at 14:26
It is indeed a bug I have same issue 2.2.2 there is the fix :github.com/magento/magento2/commit/…
– Juliano Vargas
Apr 30 '18 at 10:39
For reference to see when this is eventually fixed, this is the Magento bug in question: github.com/magento/magento2/issues/4454
– Scott Buchanan
Oct 5 '17 at 14:26
For reference to see when this is eventually fixed, this is the Magento bug in question: github.com/magento/magento2/issues/4454
– Scott Buchanan
Oct 5 '17 at 14:26
It is indeed a bug I have same issue 2.2.2 there is the fix :github.com/magento/magento2/commit/…
– Juliano Vargas
Apr 30 '18 at 10:39
It is indeed a bug I have same issue 2.2.2 there is the fix :github.com/magento/magento2/commit/…
– Juliano Vargas
Apr 30 '18 at 10:39
add a comment |
You can add custom css like below:
make an entry in layout file
<page>
<head>
<css src="css/ie-9.css" ie_condition="IE 9" />
<css src="Magento_Catalog::css/custom.css" />
<css src="Custom_SampleModule::css/custom.css"/>
</head>
</page>
add a comment |
You can add custom css like below:
make an entry in layout file
<page>
<head>
<css src="css/ie-9.css" ie_condition="IE 9" />
<css src="Magento_Catalog::css/custom.css" />
<css src="Custom_SampleModule::css/custom.css"/>
</head>
</page>
add a comment |
You can add custom css like below:
make an entry in layout file
<page>
<head>
<css src="css/ie-9.css" ie_condition="IE 9" />
<css src="Magento_Catalog::css/custom.css" />
<css src="Custom_SampleModule::css/custom.css"/>
</head>
</page>
You can add custom css like below:
make an entry in layout file
<page>
<head>
<css src="css/ie-9.css" ie_condition="IE 9" />
<css src="Magento_Catalog::css/custom.css" />
<css src="Custom_SampleModule::css/custom.css"/>
</head>
</page>
answered Nov 11 '17 at 16:20
Pramod KharadePramod Kharade
1,636928
1,636928
add a comment |
add a comment |
I found that Franck Garnier's does not quite work on 2.1.16.
I had to change the last file, Validator.php, a bit to get it to work as follows.
namespace VendorCmsLayoutFixModelLayoutUpdate;
use MagentoFrameworkAppObjectManager;
use MagentoFrameworkConfigDomUrnResolver;
use MagentoFrameworkConfigDomFactory;
use MagentoFrameworkConfigValidationStateInterface;
class Validator extends MagentoFrameworkViewModelLayoutUpdateValidator
{
const LAYOUT_SCHEMA_PAGE_HANDLE = 'page_layout';
const LAYOUT_SCHEMA_MERGED = 'layout_merged';
private $validationState;
public function __construct(
DomFactory $domConfigFactory,
UrnResolver $urnResolver,
ValidationStateInterface $validationState = null
) {
parent::__construct($domConfigFactory, $urnResolver);
$this->_xsdSchemas = [
self::LAYOUT_SCHEMA_PAGE_HANDLE => $urnResolver->getRealPath(
'urn:vendor:module:Vendor_CmsLayoutFix:etc/page_layout.xsd'
),
self::LAYOUT_SCHEMA_MERGED => $urnResolver->getRealPath(
'urn:magento:framework:View/Layout/etc/layout_merged.xsd'
),
];
}
}
WHERE:
vendor = Vendor
module = CmsLayoutFix
New contributor
add a comment |
I found that Franck Garnier's does not quite work on 2.1.16.
I had to change the last file, Validator.php, a bit to get it to work as follows.
namespace VendorCmsLayoutFixModelLayoutUpdate;
use MagentoFrameworkAppObjectManager;
use MagentoFrameworkConfigDomUrnResolver;
use MagentoFrameworkConfigDomFactory;
use MagentoFrameworkConfigValidationStateInterface;
class Validator extends MagentoFrameworkViewModelLayoutUpdateValidator
{
const LAYOUT_SCHEMA_PAGE_HANDLE = 'page_layout';
const LAYOUT_SCHEMA_MERGED = 'layout_merged';
private $validationState;
public function __construct(
DomFactory $domConfigFactory,
UrnResolver $urnResolver,
ValidationStateInterface $validationState = null
) {
parent::__construct($domConfigFactory, $urnResolver);
$this->_xsdSchemas = [
self::LAYOUT_SCHEMA_PAGE_HANDLE => $urnResolver->getRealPath(
'urn:vendor:module:Vendor_CmsLayoutFix:etc/page_layout.xsd'
),
self::LAYOUT_SCHEMA_MERGED => $urnResolver->getRealPath(
'urn:magento:framework:View/Layout/etc/layout_merged.xsd'
),
];
}
}
WHERE:
vendor = Vendor
module = CmsLayoutFix
New contributor
add a comment |
I found that Franck Garnier's does not quite work on 2.1.16.
I had to change the last file, Validator.php, a bit to get it to work as follows.
namespace VendorCmsLayoutFixModelLayoutUpdate;
use MagentoFrameworkAppObjectManager;
use MagentoFrameworkConfigDomUrnResolver;
use MagentoFrameworkConfigDomFactory;
use MagentoFrameworkConfigValidationStateInterface;
class Validator extends MagentoFrameworkViewModelLayoutUpdateValidator
{
const LAYOUT_SCHEMA_PAGE_HANDLE = 'page_layout';
const LAYOUT_SCHEMA_MERGED = 'layout_merged';
private $validationState;
public function __construct(
DomFactory $domConfigFactory,
UrnResolver $urnResolver,
ValidationStateInterface $validationState = null
) {
parent::__construct($domConfigFactory, $urnResolver);
$this->_xsdSchemas = [
self::LAYOUT_SCHEMA_PAGE_HANDLE => $urnResolver->getRealPath(
'urn:vendor:module:Vendor_CmsLayoutFix:etc/page_layout.xsd'
),
self::LAYOUT_SCHEMA_MERGED => $urnResolver->getRealPath(
'urn:magento:framework:View/Layout/etc/layout_merged.xsd'
),
];
}
}
WHERE:
vendor = Vendor
module = CmsLayoutFix
New contributor
I found that Franck Garnier's does not quite work on 2.1.16.
I had to change the last file, Validator.php, a bit to get it to work as follows.
namespace VendorCmsLayoutFixModelLayoutUpdate;
use MagentoFrameworkAppObjectManager;
use MagentoFrameworkConfigDomUrnResolver;
use MagentoFrameworkConfigDomFactory;
use MagentoFrameworkConfigValidationStateInterface;
class Validator extends MagentoFrameworkViewModelLayoutUpdateValidator
{
const LAYOUT_SCHEMA_PAGE_HANDLE = 'page_layout';
const LAYOUT_SCHEMA_MERGED = 'layout_merged';
private $validationState;
public function __construct(
DomFactory $domConfigFactory,
UrnResolver $urnResolver,
ValidationStateInterface $validationState = null
) {
parent::__construct($domConfigFactory, $urnResolver);
$this->_xsdSchemas = [
self::LAYOUT_SCHEMA_PAGE_HANDLE => $urnResolver->getRealPath(
'urn:vendor:module:Vendor_CmsLayoutFix:etc/page_layout.xsd'
),
self::LAYOUT_SCHEMA_MERGED => $urnResolver->getRealPath(
'urn:magento:framework:View/Layout/etc/layout_merged.xsd'
),
];
}
}
WHERE:
vendor = Vendor
module = CmsLayoutFix
New contributor
New contributor
answered 10 mins ago
JasonJason
1
1
New contributor
New contributor
add a comment |
add a comment |
In magento all CMS pages have an option of Layout Update XML update .Just Call your Custom code there also add CSS or JS .
Admin CMS Pages
GOTO ADMIN -> Content -> Pages -> Edit page -> Design -> Layout Update XML
add below call
<head>
<css src="Namespace_YourModule::css/styles.css"/>
</head>
this works in page layout configuration not in Layout Update XML , hope you checked...
– Mohammad Mujassam
Jul 21 '16 at 4:44
It is working fine I have tested this code . just remove "Namespace_YourModule::" and set in to "Layout Update XML" and refresh you Cache so you can show in that page only.
– Hitesh Vaghasiya
Jul 21 '16 at 18:59
1
Please correct the XML data and try again. Element 'head': This element is not expected. Expected is one of ( referenceContainer, container, update, move ). Line: 1
this we will get if we put anything else apart from above four Element. I am using magento 2.0.7
– Mohammad Mujassam
Jul 22 '16 at 4:40
1
Yeah, this worked for me. Just remember to flush the cache after you change the layout for the cms page to pickup the change.
– Dallas Clarke
Dec 13 '17 at 3:23
add a comment |
In magento all CMS pages have an option of Layout Update XML update .Just Call your Custom code there also add CSS or JS .
Admin CMS Pages
GOTO ADMIN -> Content -> Pages -> Edit page -> Design -> Layout Update XML
add below call
<head>
<css src="Namespace_YourModule::css/styles.css"/>
</head>
this works in page layout configuration not in Layout Update XML , hope you checked...
– Mohammad Mujassam
Jul 21 '16 at 4:44
It is working fine I have tested this code . just remove "Namespace_YourModule::" and set in to "Layout Update XML" and refresh you Cache so you can show in that page only.
– Hitesh Vaghasiya
Jul 21 '16 at 18:59
1
Please correct the XML data and try again. Element 'head': This element is not expected. Expected is one of ( referenceContainer, container, update, move ). Line: 1
this we will get if we put anything else apart from above four Element. I am using magento 2.0.7
– Mohammad Mujassam
Jul 22 '16 at 4:40
1
Yeah, this worked for me. Just remember to flush the cache after you change the layout for the cms page to pickup the change.
– Dallas Clarke
Dec 13 '17 at 3:23
add a comment |
In magento all CMS pages have an option of Layout Update XML update .Just Call your Custom code there also add CSS or JS .
Admin CMS Pages
GOTO ADMIN -> Content -> Pages -> Edit page -> Design -> Layout Update XML
add below call
<head>
<css src="Namespace_YourModule::css/styles.css"/>
</head>
In magento all CMS pages have an option of Layout Update XML update .Just Call your Custom code there also add CSS or JS .
Admin CMS Pages
GOTO ADMIN -> Content -> Pages -> Edit page -> Design -> Layout Update XML
add below call
<head>
<css src="Namespace_YourModule::css/styles.css"/>
</head>
answered Jul 20 '16 at 14:46
Hitesh VaghasiyaHitesh Vaghasiya
4711416
4711416
this works in page layout configuration not in Layout Update XML , hope you checked...
– Mohammad Mujassam
Jul 21 '16 at 4:44
It is working fine I have tested this code . just remove "Namespace_YourModule::" and set in to "Layout Update XML" and refresh you Cache so you can show in that page only.
– Hitesh Vaghasiya
Jul 21 '16 at 18:59
1
Please correct the XML data and try again. Element 'head': This element is not expected. Expected is one of ( referenceContainer, container, update, move ). Line: 1
this we will get if we put anything else apart from above four Element. I am using magento 2.0.7
– Mohammad Mujassam
Jul 22 '16 at 4:40
1
Yeah, this worked for me. Just remember to flush the cache after you change the layout for the cms page to pickup the change.
– Dallas Clarke
Dec 13 '17 at 3:23
add a comment |
this works in page layout configuration not in Layout Update XML , hope you checked...
– Mohammad Mujassam
Jul 21 '16 at 4:44
It is working fine I have tested this code . just remove "Namespace_YourModule::" and set in to "Layout Update XML" and refresh you Cache so you can show in that page only.
– Hitesh Vaghasiya
Jul 21 '16 at 18:59
1
Please correct the XML data and try again. Element 'head': This element is not expected. Expected is one of ( referenceContainer, container, update, move ). Line: 1
this we will get if we put anything else apart from above four Element. I am using magento 2.0.7
– Mohammad Mujassam
Jul 22 '16 at 4:40
1
Yeah, this worked for me. Just remember to flush the cache after you change the layout for the cms page to pickup the change.
– Dallas Clarke
Dec 13 '17 at 3:23
this works in page layout configuration not in Layout Update XML , hope you checked...
– Mohammad Mujassam
Jul 21 '16 at 4:44
this works in page layout configuration not in Layout Update XML , hope you checked...
– Mohammad Mujassam
Jul 21 '16 at 4:44
It is working fine I have tested this code . just remove "Namespace_YourModule::" and set in to "Layout Update XML" and refresh you Cache so you can show in that page only.
– Hitesh Vaghasiya
Jul 21 '16 at 18:59
It is working fine I have tested this code . just remove "Namespace_YourModule::" and set in to "Layout Update XML" and refresh you Cache so you can show in that page only.
– Hitesh Vaghasiya
Jul 21 '16 at 18:59
1
1
Please correct the XML data and try again. Element 'head': This element is not expected. Expected is one of ( referenceContainer, container, update, move ). Line: 1
this we will get if we put anything else apart from above four Element. I am using magento 2.0.7– Mohammad Mujassam
Jul 22 '16 at 4:40
Please correct the XML data and try again. Element 'head': This element is not expected. Expected is one of ( referenceContainer, container, update, move ). Line: 1
this we will get if we put anything else apart from above four Element. I am using magento 2.0.7– Mohammad Mujassam
Jul 22 '16 at 4:40
1
1
Yeah, this worked for me. Just remember to flush the cache after you change the layout for the cms page to pickup the change.
– Dallas Clarke
Dec 13 '17 at 3:23
Yeah, this worked for me. Just remember to flush the cache after you change the layout for the cms page to pickup the change.
– Dallas Clarke
Dec 13 '17 at 3:23
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%2f126646%2fmagento2-how-to-add-different-custom-css-file-on-specific-cms-pages%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