I'm just started Magento and recently have some issues. So, this is what I want to do: I want to display Notices at the top of the site as following Image.

Eg: I want to show some Discount Coupons on the Top of the site, I want to add that message in backend side and the it will show the customers.

enter image description here

  • Did you get my answer? – Prince Patel Jun 1 '17 at 13:13
  • @PrincePatel yes. but didn't clear "Now create static block from admin which contain your discount message. and call block in notices.phtml file to show your discount notice at top of the site" part. could u explain it ? – Amal Madawa Jun 5 '17 at 6:08
  • Create static block from admin content->block->add new block and enter your discount message in static block. Then call this new static block in notice.phtml with block identifier. – Prince Patel Jun 5 '17 at 6:20
  • @PrincePatel. where to use following code ? <?php echo $block->getLayout()->createBlock('Magento\Cms\Block\Block')->setBlockId('block_identifier')->toHtml();?> – Amal Madawa Jun 5 '17 at 6:58
  • i did but. it works without that code. why should it add to notice.phtml ? – Amal Madawa Jun 5 '17 at 10:37

---- First Method-----

Create new widget by

1) go to CONTENT > Widgets and add widget

2) Choose your theme and type: CMS Static Block

3) In layout updates

Display on: All Pages

Container: Page Top

enter image description here

5) In Widget Options select your static block which contain your discount message

-----Second Method-----

Override notices.phtml in your theme.



To your theme


Now create static block from admin and enter your discount message. Then call this static block in notices.phtml file to show your discount notice at top of the site

<?php echo $block->getLayout()->createBlock('Magento\Cms\Block\Block')->setBlockId('block_identifier')->toHtml();?>
| improve this answer | |
  • @khoa TruongDinh Yes it's match with your answer. Sorry for that. You are my senior and I learnt about Magento 2 with your posts :) – Prince Patel Jun 11 '17 at 4:42
  • Ha..ha.. Yeah! Okay! Never mind! – Khoa TruongDinh Jun 11 '17 at 7:04

AFAIK, we can use Widget: CONTENT > Widgets. Choose CMS static Block type. In the Layout Updates. Choose Page Top container (need to test again, not test yet): enter image description here

| improve this answer | |
  • How this can be done pro-grammatically? any suggesions – jafar pinjar Nov 29 '19 at 13:55

The Best way to do this is using Magento build in widgets. Please follow the given instructions:

  1. Create a new static block in admin that will contain your coupon code HTML.

  2. Create a new widget as follow:

    Content >> Widgets >> Click "Add widget" Button.

From the widget form, select the following:

StoreFront Properties Tab

Type => CMS static block

Design Theme => Your custom theme (Press continue button)

Widget Title => Widget Name

Assign to Store Views => All

Layout Updates Section:

Display On => All Pages

Container => Page Header 

Widget Option Tab

Select the newly created static block here

This is how you can show your custom messages at the top of the page.

enter image description here

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.