To not edit Magento files, I need to write a mini module.
Create the following folders :
- app\code\MyCustom
- app\code\MyCustom\CustomWidget
To register the module, create a registration.php file in the app\code\MyCustom\CustomWidget folder with the following code :
<?php
\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
'MyCustom_CustomWidget',
__DIR__
);
Now that we have a module folder, we need to create a module.xml file in the app\code\MyCustom\CustomWidget\etc folder with the following code :
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="MyCustom_CustomWidget" setup_version="1.0.0"/>
</config>
We need to create a widget.xml file, where there will be a new position, in the app\code\MyCustom\CustomWidget\etc folder with the following code :
<?xml version="1.0" encoding="UTF-8"?>
<widgets xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Widget:etc/widget.xsd">
<widget id="new_products" class="Magento\Catalog\Block\Product\Widget\NewWidget" is_email_compatible="true"
placeholder_image="Magento_Catalog::images/product_widget_new.png" ttl="86400">
<containers>
<container name="content.new">
<template name="grid" value="default" />
<template name="list" value="list" />
</container>
</containers>
</widget>
</widgets>
Now we need to create a position for your custom theme
app\design\frontend\package\theme\Magento_Theme\layout\default.xml
<?xml version="1.0"?>
<page layout="3columns" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceContainer name="main">
<container name="content.new" label="New Container"/>
</referenceContainer>
</body>
</page>
The result of such
