Show TOC

Instantiating Fragments in Declarative ViewsLocate this document in the navigation structure

Example, how all three types of fragments can be instantiated in an XML view.

Context

In XML views, fragments are used like regular controls, or more precisely, like views.

The following code example shows an XML view that includes all three types of fragments, that is an XML fragment, a JS fragment and an HTML fragment. Each type is instantiated once without a given ID and once with a given ID. These fragment references basically work like import statements including the fragment content controls.

<mvc:View xmlns:mvc="sap.ui.core.mvc" xmlns:core="sap.ui.core" xmlns:commons="sap.ui.commons" controllerName="testdata.fragments.XMLViewController" >
    
    <commons:HorizontalDivider />
    
    <core:Fragment               fragmentName="my.useful.SimpleUiPart" type="XML" />
    <core:Fragment id="xmlInXml" fragmentName="my.useful.SimpleUiPart" type="XML" />
    
    <commons:HorizontalDivider />
    
    <core:Fragment              fragmentName="my.useful.UiPartX" type="JS" />
    <core:Fragment id="jsInXml" fragmentName="my.useful.UiPartX" type="JS" />
    
    <commons:HorizontalDivider />
    
    <core:Fragment                fragmentName="my.useful.UiPartZ" type="HTML" />
    <core:Fragment id="htmlInXml" fragmentName="my.useful.UiPartZ" type="HTML" />

        
</mvc:View>