Expand my Community achievements bar.

SOLVED

InvalidTemplateException while creating content fragment - ContentFragmentManager API

Avatar

Level 1

Hi,

I am trying to create a content fragment using com.adobe.cq.dam.cfm.ContentFragmentManager create method. I tried giving different content fragment model resources at create(Resource parent, Resource template, String name, String title). It always giving com.adobe.cq.dam.cfm.impl.InvalidTemplateException: Invalid template format; missing 'version' attribute.

Am I missing anything here?

@Reference

ContentFragmentManager cfm;

--

Resource parent = resourceResolver().getResource("/content/dam/fragments");

Resource template = resourceResolver().getResource("/conf/global/settings/dam/cfm/models/custommodel");// content fragment model in my local

ContentFragment contentFragment = cfm.create(parent, template, "samplefragmentname", "sample fragment title");

resourceResolver().commit();

Thanks,

Raja

1 Accepted Solution

Avatar

Correct answer by
Level 10

CF Model is not same as CF Template. That's the issue in this case. Either you create a CF template or use an existing editable template for the same. Create a CF manually and you'd get to know more about it.

Resource template = resourceResolver().getResource("/conf/global/settings/dam/cfm/models/custommodel");  // provide template path rather than CF model path

Refer - Content Fragment Templates

View solution in original post

4 Replies

Avatar

Correct answer by
Level 10

CF Model is not same as CF Template. That's the issue in this case. Either you create a CF template or use an existing editable template for the same. Create a CF manually and you'd get to know more about it.

Resource template = resourceResolver().getResource("/conf/global/settings/dam/cfm/models/custommodel");  // provide template path rather than CF model path

Refer - Content Fragment Templates

Avatar

Level 1

I tried with template. It is working. Thanks Gaurav!

Thanks,

Raja

Avatar

Level 1

Can you please share the template path you used?

Avatar

Level 1

I used OOB simple template

/libs/settings/dam/cfm/templates/simple/jcr:content