You can write your own Twig templates in PHP and then use them in any widget. This is useful when several widgets need the same piece of HTML.
Step 1
In the functions.php file of your theme, or in a code snippet, add your templates with the uelm_get_twig_templates filter. Each template has a name and Twig content:
function addMyTemplates($arrMyTemplates){
$arrMyTemplates["mytemplate"] = "{{title}}";
return($arrMyTemplates);
}
add_filter("uelm_get_twig_templates", "addMyTemplates");
The older filter name ue_get_twig_templates still works too.
Step 2
In the HTML of your widget, show the template with ucfunc(“render”) and the template name:
{{ ucfunc("render", "mytemplate") }}
The template gets the same data as the widget, so you can use all the attributes of the widget in it. When you use it in the Item HTML, it gets the data of the current item.