Widget

Use the 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 id="mage2gen_module_test" class="Mage2Gen\Module\Block\Widget\Test">
		<label>Test</label>
		<description>Test</description>
		<parameters>
			<parameter name="test" xsi:type="text" visible="true" sort_order="10">
				<label>Test</label>
			</parameter>
		</parameters>
	</widget>
</widgets>

Block/Widget/Test.php

<?php
declare(strict_types=1);

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";

}