A lightweight Magento 2 module that renders a configurable banner at the very top of every page. The banner can be enabled/disabled per scope and its text and colors can be customized from the Admin. Both Luma and Hyvä compatible.
- Magento 2.4.x
Install via Composer (recommended):
composer require imi/magento2-top-headerThen enable and register the module:
bin/magento module:enable IMI_TopHeader
bin/magento setup:upgrade
bin/magento cache:flushIf you are in production mode, also deploy static content as usual:
bin/magento setup:static-content:deploy -fNavigate to: Stores > Configuration > iMi > Top Header.
Scope support: Global, Website, Store View.
Available options:
imi_topheader/general/enable— Enable/disable the banner (Yes/No)imi_topheader/general/text— Banner text (supports HTML; processed through Magento's template filter)imi_topheader/general/text_color— Text color (hex or valid CSS color)imi_topheader/general/background_color— Background color (hex or valid CSS color)
- Registration:
src/registration.php - Layout injection:
src/view/frontend/layout/default.xml- Adds a container
top.headerbeforepage.wrapperand renders blockIMI\TopHeader\Block\BannerTextwith templateIMI_TopHeader::topheader.phtmlwhenimi_topheader/general/enableis true.
- Adds a container
- Hyvä override:
src/view/frontend/layout/hyva_default.xml- Reuses the same block but switches template to
IMI_TopHeader::hyva/topheader.phtmlwhen using the Hyvä theme.
- Reuses the same block but switches template to
- Block:
IMI\TopHeader\Block\BannerText(insrc/Block/BannerText.php)- Reads configuration values and passes them to the view. The
textvalue is filtered via Magento's widget/template filter.
- Reads configuration values and passes them to the view. The
- Luma/Blank and similar themes: template
src/view/frontend/templates/topheader.phtmlis used by default. - Hyvä theme: template
src/view/frontend/templates/hyva/topheader.phtmlis used viasrc/view/frontend/layout/hyva_default.xml.
You can customize the look by overriding the corresponding PHTML in your theme, or by adjusting the configuration colors.
This project is licensed under the MIT License. See the LICENSE file for details.