In the previous recipes, we prepared the module for the real work. We added the most common features to the module so that we can easily extend it with the new functionality.
In this recipe, we will create a block of new products to the page we created in the previous recipes.
In our module, we will create a block that will load a product collection. This product collection will be used in the template, which will show the newest products of the shop.
Ensure that you have the module of the previous recipe installed.
The following steps demonstrate how to start with adding the block with new products:
To create the block class, we have to create the
Newproducts.php
file in theapp/code/Packt/HelloWorld/Block/
folder.Add the following content to that file:
<?php namespace Packt\HelloWorld\Block; use Magento\Framework\View\Element\Template; class Newproducts extends Template { }