Load css on condition
Question
I need to a CSS file based on customer attribute when the user is logged.
How can I do this ?
Readed this : https://mage2.pro/t/topic/140 but it's based on backend config.
Solution
Solution : If it helps, i've added a event in my event.xml
<event name="controller_action_predispatch">
<observer name="addCSS" instance="Vendore\Module\Observer\AddCSS" shared="false" />
</event>
the related observer :
public function execute(Observer $observer){
$om = \Magento\Framework\App\ObjectManager::getInstance();
$page = $om->get('Magento\Framework\View\Page\Config');
$condition = $this->getConditionResult();
if($condition){
$page->addPageAsset('Magento_Theme::css/otherCSS.css');
}
}
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange