Block

Creates just a Block

Create a Simple Block for the Frontend or Adminhtml. It is also possible to insert the block based on a layout handle and a reference.

Example

Create a Notice Block

Input for the block form

  • classname: Notices
  • methodname: getCustomNotice
  • scope: Frontend
  • layout handle: default
  • reference type: Container
  • reference name: content

Use the Block snippet in the Magento 2 module creator.

Files

view/frontend/templates/test.phtml

<?php
/**
 * @var $block \Mage2Gen\Module\Block\Test
 */
?>
<div>
	<?= $block->Test() ?>
	<?= __('Hello Mage2Gen_Module::test.phtml') ?>
</div>

Block/Test.php

<?php


namespace Mage2Gen\Module\Block;

class Test
{

    /**
     * @return string
     */
    public function Test()
    {
        //Your block code
        return 'Hello World!';
    }
}