27.07.2016

Magento 2. Creating a module. Part III.

(We need the module that we created in the previous recipes)

Adding a block with new products

STEP I – Create the block class:

Create a folder:

app/code/Magedd/Education/Block

 

Create a file:

app/code/Magedd/Education/Block/Newproducts.php

STEP II – Create a template:

Create a folder:

app/code/Magedd/Education/view/frontend/templates

 

Create a file:

app/code/Magedd/Education/view/frontend/templates/newproducts.phtml

STEP III –  Adding the block to the page:

Change file:

app/code/Magedd/Education/view/frontend/layout/magedd_index_index.xml

add the following code as a child of <body>*

STEP IV – Clear the cache by CLI

 

/var/www/local/{your-project-name.dev} > rm -rf var/generation/

/var/www/local/{your-project-name.dev} > php bin/magento cache:flush

/var/www/local/{your-project-name.dev} > php bin/magento cache:clean

 

Now you can check your page on:

htttp://{your-project-name.dev}/magedd

*            *           *

* – the structure of magedd_index_index.xml file: