Skip to Content
0

How to load a fragment with xml templating?

May 16 at 06:35 AM

53

avatar image
Former Member

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?

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

2 Answers

avatar image
Former Member
May 16 at 10:13 AM
0

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>
Show 2 Share
10 |10000 characters needed characters left characters exceeded
Former Member

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:// . hana.ondemand.com/sap/ui5/1/resources/~201802081542~/http://schemas/sap/com/sapui5/extension/sap/ui/core/template/1/with.js 404 (Not Found)

0
Former Member

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.

0
Sharath M G May 16 at 12:40 PM
0

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

Show 3 Share
10 |10000 characters needed characters left characters exceeded
Former Member

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>

0
Try in this line: 
<template:with path="ovpCardProperties>/annotationPath" helper="sap.ovp.cards.AnnotationHelper.resolveEntityTypePath" var="lineItem">
0
Former Member
Sharath M G

This did not work :( . Getting the same error

0