5

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

7
  • Did you get my answer? Jun 1, 2017 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 ? Jun 5, 2017 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. Jun 5, 2017 at 6:20
  • @PrincePatel. where to use following code ? <?php echo $block->getLayout()->createBlock('Magento\Cms\Block\Block')->setBlockId('block_identifier')->toHtml();?> Jun 5, 2017 at 6:58
  • i did but. it works without that code. why should it add to notice.phtml ? Jun 5, 2017 at 10:37

3 Answers 3

13

Method 1:

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

  1. In Widget Options select your static block which contain your discount message

Method 2:

Override notices.phtml in your theme.

From

vendor/magento/module-theme/view/frontend/templates/html/notices.phtml

To your theme

app/design/frontend/Vendor/theme/Magento_Theme/templates/html/notices.phtml

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();?>
1
  • Ha..ha.. Yeah! Okay! Never mind! Jun 11, 2017 at 7:04
3

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

1
  • How this can be done pro-grammatically? any suggesions Nov 29, 2019 at 13:55
0

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

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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