- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-04-2020
01:43 AM
06-04-2020
01:43 AM
Magento 2 - widget, add css to block
I want to insert a css fom the widget block in the magento head but cannot achieve this, i am using:
namespace Vendor\Module\Block\Widget; use Magento\Framework\View\Element\Template; use Magento\Widget\Block\BlockInterface; class Sliderimage extends Template implements BlockInterface { protected function _construct() { parent::_construct(); $this->setTemplate('widget/sliderimage.phtml'); } /** * @return $this */ protected function _prepareLayout() { $this->pageConfig->addPageAsset('Vendor_Module::css/sliderimage.css'); return parent::_prepareLayout(); } }
What am i missing?
Thank you,
Damien.
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-04-2020
02:56 AM
06-04-2020
02:56 AM
Re: Magento 2 - widget, add css to block
Hello @KennedyA
protected function _construct() { $om = \Magento\Framework\App\ObjectManager::getInstance(); $page = $om->get('Magento\Framework\View\Page\Config'); $page->addPageAsset('Vendor_Extension::css/yourstyles.css'); }
please check above code
Hope it will help you
Problem solved? Click Kudos & Accept as Solution!
Sunil Patel
Magento 2 Certified Professional Developer & Frontend Developer
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-04-2020
05:25 AM
06-04-2020
05:25 AM
Re: Magento 2 - widget, add css to block
Hi @KennedyA
Kindly refer below url :
https://webkul.com/blog/magento2-how-to-add-css-and-js-file-in-module/
It will help you to resolve you issue.
If issue resolve, Please click on 'Kudos' & Accept as Solution!
Problem solved? Click Accept as Solution!
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-04-2020
05:58 AM
06-04-2020
05:58 AM
Re: Magento 2 - widget, add css to block
Hi, thank you but i want to add this asset only on page displaying the
widget.
widget.