Widget

Use the Widget snippet in the Magento 2 module creator.

Files

view/frontend/templates/widget/Test.phtml

<?php if($block->getData('test')): ?>
	<h2 class='test'><?php echo $block->getData('test'); ?></h2>
<?php endif; ?>

etc/widget.xml

<?xml version="1.0" ?>
<widgets xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Widget:etc/widget.xsd">
	<widget class="Mage2Gen\Module\Block\Widget\Test" id="mage2gen_module_test">
		<label>Test</label>
		<description>Test</description>
		<parameters>
			<parameter name="test" sort_order="10" visible="true" xsi:type="text">
				<label>Test</label>
			</parameter>
		</parameters>
	</widget>
</widgets>

Block/Widget/Test.php

<?php


namespace Mage2Gen\Module\Block\Widget;

use Magento\Framework\View\Element\Template;
use Magento\Widget\Block\BlockInterface;

class Test extends Template implements BlockInterface
{

    protected $_template = "widget/test.phtml";

}