Create a content fragment using a workflow? | Community
Skip to main content
New Participant
May 23, 2022
Solved

Create a content fragment using a workflow?

  • May 23, 2022
  • 2 replies
  • 813 views

Hi, i need to create a Content Fragment using workflow, is there some way to do it? Or there's some workflow components that allows me to do that?

 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by SantoshSai

Hi @fedeperez 

Here sharing some sample code you can refer and implement in workflow.

To create a content fragment, you can use ‘create’ API reference from ‘com.adobe.cq.dam.cfm ContentFragmentManager’.

 

//reference the Content Fragment Manager @reference private ContentFragmentManager fragmentManager; private void createFrag() { /** fragmentManager.create helps to create a content fragment parent – The location where the content fragment should be created (for eg. “/content/dam/fragments”) template – the content fragment template to refer while creating the new fragment my-test-fragment – name of the fragment My Test Fragment – title of the fragment **/ ContentFragment myFragment = fragmentManager.create(parent, template, “my-test-fragment”, “My Test Fragment”); }

 

Programmatically accessing a content fragment

We need ‘com.adobe.cq.dam.cfm.ContentFragment’ API reference to access a content fragment

 

//Get the resource of content fragment as below. Resource fragmentResource = resourceResolver.getResource(“/content/dam/fragments/my-test-fragment”); //Adapt it to a fragment resource if (fragmentResource != null) { ContentFragment fragment = fragmentResource.adaptTo(ContentFragment.class); // the resource is now accessible through the API }

 

 

Reference:
1. https://helpx.adobe.com/experience-manager/6-5/sites/developing/using/reference-materials/javadoc/co...

2. https://engineering.icf.com/aem-content-fragments-as-an-api/


Hope that helps you!

 

Regards,

Santosh

 

 

2 replies

SantoshSai
SantoshSaiAccepted solution
New Participant
May 23, 2022

Hi @fedeperez 

Here sharing some sample code you can refer and implement in workflow.

To create a content fragment, you can use ‘create’ API reference from ‘com.adobe.cq.dam.cfm ContentFragmentManager’.

 

//reference the Content Fragment Manager @reference private ContentFragmentManager fragmentManager; private void createFrag() { /** fragmentManager.create helps to create a content fragment parent – The location where the content fragment should be created (for eg. “/content/dam/fragments”) template – the content fragment template to refer while creating the new fragment my-test-fragment – name of the fragment My Test Fragment – title of the fragment **/ ContentFragment myFragment = fragmentManager.create(parent, template, “my-test-fragment”, “My Test Fragment”); }

 

Programmatically accessing a content fragment

We need ‘com.adobe.cq.dam.cfm.ContentFragment’ API reference to access a content fragment

 

//Get the resource of content fragment as below. Resource fragmentResource = resourceResolver.getResource(“/content/dam/fragments/my-test-fragment”); //Adapt it to a fragment resource if (fragmentResource != null) { ContentFragment fragment = fragmentResource.adaptTo(ContentFragment.class); // the resource is now accessible through the API }

 

 

Reference:
1. https://helpx.adobe.com/experience-manager/6-5/sites/developing/using/reference-materials/javadoc/co...

2. https://engineering.icf.com/aem-content-fragments-as-an-api/


Hope that helps you!

 

Regards,

Santosh

 

 

Santosh Sai