For each fragment type, OpenUI5 provides a method that can be used to programmatically instantiate a fragment.
To give an example of a programmatic instantiation of an HTML fragment, you first have to define one. The following code presents an example definition:
#js<div data-sap-ui-type="sap.m.Button" data-press="doSomething" data-text="Hello World"></div>
This fragment can be instantiated from a controller as follows:
#!jsvar myButton = sap.ui.htmlfragment("my.useful.UiPartZ", oController); // this specific fragment again needs a controller
This instantiation can be done at any place in the code, given that a controller is available and the returned button can be used like any button.