cancel
Showing results for 
Search instead for 
Did you mean: 

How to load a fragment with xml templating?

0 Kudos

Hi ,

I have a xml fragment which has xml tempalte <template:with>... When i try to laod this tempalte in the controller using the sap.ui.xmlfragment() constructor it throws error that template.js is not found. How can I pre-process this fragment and load this fragment inside the controller?

Accepted Solutions (0)

Answers (2)

Answers (2)

Sharathmg
Active Contributor
0 Kudos

do you have the property rel=preload while using the template? If yes try it.

0 Kudos

Where should i include this exactly? My fragment is as below:

<core:FragmentDefinition
        xmlns="sap.m" 
        xmlns:core="sap.ui.core"
        xmlns:layout="sap.ui.layout"
        xmlns:template="http://schemas.sap.com/sapui5/extension/sap.ui.core.template/1"
        xmlns:build="sap.build">
		<layout:content>			
	        <template:with path="ovpCardProperties>/annotationPath" helper="sap.ovp.cards.AnnotationHelper.resolveEntityTypePath" var="lineItem">
	        	<!-- Sap ui5 controls -->
	   		</template:with>
        </layout:content>
</core:FragmentDefinition>

Sharathmg
Active Contributor
0 Kudos
Try in this line: 
<template:with path="ovpCardProperties>/annotationPath" helper="sap.ovp.cards.AnnotationHelper.resolveEntityTypePath" var="lineItem">
0 Kudos

This did not work 😞 . Getting the same error

0 Kudos

I am not sure where and how you are using "<template:with>", but SAPUI5 is looking for template.js to be able to handle the control. So template.js is not defined at project level.

The JS files (namespaces) for XML elements (controls) are defined in the first level of XML.

For example:

<core:FragmentDefinition xmlns="sap.m" xmlns:core="sap.ui.core">   
   <Dialog id="helloDialog" title="Hello {/recipient/name}">    </Dialog>
</core:FragmentDefinition>
0 Kudos

My template is in a file called 'orders.fragment.xml' as below :

<core:FragmentDefinition
        xmlns="sap.m" 
        xmlns:core="sap.ui.core"
        xmlns:layout="sap.ui.layout"
        xmlns:template="http://schemas.sap.com/sapui5/extension/sap.ui.core.template/1"
        xmlns:build="sap.build">			
	<template:with path="ovpCardProperties>/annotationPath" helper="sap.ovp.cards.AnnotationHelper.resolveEntityTypePath"          var="lineItem">
	        	<!-- Sap ui5 controls -->
	</template:with>
</core:FragmentDefinition>
<br>

Then in my javascript I try to load the fragment as below :

var orderFragment = sap.ui.xmlfragment(this.getView().getId(), "sap.container.orders", this);<br>

This line then throws the error : GET https://<tenent-name>.hana.ondemand.com/sap/ui5/1/resources/~201802081542~/http://schemas/sap/com/sa... 404 (Not Found)

0 Kudos

I never used absolute URL in XML namespace definition and I do not think this is allowed by CORS anyway. You might be better off downloading the JS file into a project folder and add the relative path. Or there is some workaround with the "neo-app.json" file or with "manifest.json" by defining path or resource.