Adding static blocks to pages through widgets

Adding a static block to a page can also be done with the Magento widgets system; this allows you to add blocks to pages without the knowledge of how layout XML works.

How to do it…

In this recipe, we will see step by step how to add a static block to the home page:

  1. Create a new static block through the Magento backend. Go to the Content menu option and select Blocks under the Elements menu. Next, click on the Add New Block button to create a new block. Create the block with the content you want and click on Save Block:
    How to do it…
  2. Create a new widget. Go to the Content menu option and select Widgets under the Elements menu. Next, click on the Add Widget button to create a new widget. Select the CMS Static Block option for the Type field and the theme that you want to apply this widget to under Design Theme. After this, click on the Continue button:
    How to do it…
  3. Specify the Widget Title, Assign to Store Views, and Sort Order properties:
    How to do it…
  4. Specify the layout options; here, we configure the page and container where the content must be visible. It is possible to select multiple locations for the same block:
    How to do it…
  5. The last step is to select the block to display. For this, go to the Widget Options tab and click on the Select Block button. From the list shown, you can now select the block that you want to add:
    How to do it…
  6. Refresh the cache:
    bin/magento cache:clean
  7. Refresh the home page and check whether the created block is shown.

How it works…

The widget created will build the layout XML for the details that you have selected and will be loaded from the database while generating the layout. It is possible to add multiple Layout Updates and select multiple locations where the widget should be shown.

Available widgets

By default, Magento ships with the following widgets:

CMS Page Link

The CMS Page Link widget will allow you to add a link to a page that you specify; this can be useful to add a link to the footer.

CMS Static Block

The CMS Static Block widget will add a static block to the location that you specify (as shown in this recipe).

Catalog Category Link

The Catalog Category Link widget adds a link to a specific category that you specify.

Catalog New Products List

The Catalog New Products List widget allows you to add a list of products to a page; here, you can select the amount of products that you want to show and if you want to display only new products or all products.

Catalog Product Link

With the Catalog Product Link widget, it is possible to create a link to a specific product.

Catalog Product List

To display a list of products on your page, you can use the Catalog Product List widget. With this widget, you can control the products shown based on your own conditions (product attributes).

Orders and Returns

This will add a block to allow customers to search for their orders and view the status or request for a return (Enterprise).

Recently Compared Products

This will add a block that shows the products that are added to the compare products list.

Recently Viewed Products

This will add a block that shows the products that have been viewed by the user.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.16.79.65