Friday, 30 June 2017

Step by step tutorial on Creating Experience Fragments in AEM


In my previous blog, I have explained the basics of Experience Fragments in AEM. Here I will walk you through the process of creating an Experience Fragment and authoring it to a page. Remember Experience Fragments can be authored on third party systems too, for the demo I am using a test AEM page.

Steps

After loggin into AEM, click on 'Experience Fragments' , then from create button click on the 'Experience Fragment'. The folder option aloows us to categorise the Experience Fragments.



Once created, start filling out the details in properties section and 'First Variant'  as shown below.



On the 'First Variant' section select the template for the Experience Fragment. HTML fragment which I am going to select is a default provided by AEM.




Now select the created Experience Fragment, and click on edit option.



We will have authoring page opened for the Experience Fragment. We can author assets, components and variations for a fragment.



In assets section, I have authored an image ( We.Retail instore image).



In variations, we can click on 'create' to authore variations.



Start filling the variations. The template can be any default Experience Fragment template.



Below given various menu options on the Experience Fragment authoring.



Once done with Experience Fragment creation, we will go ahead and author the fragment on a page. For this I have created a test page.
On this page, author an Experience Fragment as a component('Drag COmponents here').



Once this is done we can see the Experience Fragment is rendered on the test page as shown below.

Click me to watch The YouTube demo video



Thursday, 29 June 2017

AEM Experience Fragment Basics


What is an experience fragment?
An 'Experience Fragment' is a collection of components with its own content and layout.

  • Each Experience Fragment is based on a template which gives a structure.
  • Each experience fragment has one/many components with its own layout.
  • Each experience itself makes sense.
  • Created with intention of reuse, re ordered, resized.
  • Experience Fragments works on Caas model, with each fragment can be created with multiple variations.


Scenarios when an AEM Experience Fragment to be used?
There are times when we need to replicate same type of page section in other pages. 'Experience Fragments' can help us saving time in this case. Also cases like AEM is used as headless CMS, where AEM to be just used as content storage, not for delivery. In this case AEM Experience Fragment will be available for a third party rendering system for consuming.

Cases when we need multiple version of content, Experience Fragments are a good option.

Additional notes:

Experience Fragments allow to manage sections of experiences that can easily be reused and distributed. They are template based and allow live copy relationship. At present AEM 6.3 supports Experience fragments to html5 web templates, Pinterest and Facebook templates. Custom templates can be created if required.

Tuesday, 27 June 2017

How to create a Content Fragment? step by step tutorial

Content Fragment helps to author content without creating a Page. Content Fragments are useful in displaying content across channels like web pages, mobile apps or campaigns.

What are all, a Content Fragment can hold?

Content Fragment has well defined content structure, which can hold text segments and references to assets, likes images, videos etc.

Related contents
AEM Leading to head less CMS?
AEM Content Fragment output as JSON
AEM 6.3 Content Fragments Basics
How to create a Content Fragment? step by step tutorial
Create & Access the content fragment programmatically

Creating Content Fragments

To start with , go to Assets > Files > Click on Create , Content Fragment



Select the template as shown(Default Simple Fragment Template). We can either have our new templates created based on the content requirement or use the default one.



In 'Properties' section fill up the basic details of this fragment.



Advanced section will have an auto populated name. We can edit it in case we need our custom property/url here.



Click on 'Create' will show you the success message as shown below. On clicking 'Done' will show the new Content Fragment.



The created Content Fragment can be downloaded as shown below. The downloaded fragment can have all related information selected while creation. Unzipping the fragment displays the folder contents.



Unzipped file will have a metadata file with all information.



There are many options for a Content Fragment once created. The header bar will have options like download, checkout, edit, manage tags, adding collections publish, un-publish etc.



Edit options for a content fragment is quiet flexible, through which we can update the textual content, inserting other assets, uploading content from a document etc. We can see a live update of content with word count, character count etc during content entry.



On selecting and editing the dialog gives 'Create variation' option. Through which we can create different version of content based on our requirement. These variations are used across different channels.



Clicking the 'folder' icon provides us the option to add collection to this content fragment.



On clicking 'metadata' section helps to update the metadata associate with the fragment.



Once all updates are done, save the content fragment to ensure all changes are submitted to crx. The new content fragment created can be found at path '/content/dam'.

YouTube demo videos for Content Fragments:
         AEM 6.3 Content Fragments Basics
         Content Fragments AEM
         View Content fragment output in aem

Create & Access the content fragment programmatically

Content Fragment helps to create content without referring a page. This fragments can be used to showcase the content across various channels.
You can read multiple blogs on the same here.
AEM Leading to head less CMS?
AEM Content Fragment output as JSON
AEM 6.3 Content Fragments Basics
How to create a Content Fragment? step by step tutorial
Create & Access the content fragment programmatically

Programmatic creation, access, modification of Content Fragment

To create a content fragment, we need 'create' API reference from 'com.adobe.cq.dam.cfm.
ContentFragmentManager'.

Once we have the import, use below code to create a content fragment programmatizally.

//reference the Content Fragment Manager
@Reference
private ContentFragmentManager fragmentManager;

private void myCreateFun() {
    /** 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
}


Programmatically accessing elements from Content Fragment

Iterator<ContentElement> elements = fragment.getElements();
while (elements.hasNext()){
ContentElement element = elements.next();
//your action on element
}

Programmatically Accessing Content Fragment metadata:

Map<String, Object> getMetaData();


Programmatically Accessing Content Fragment variations:

Iterator<ContentVariation> variations = element.getVariations();

while(variations.hasNext()){
ContentVariations variation = variations.next();
//do the variation process here
}

Programmatically Accessing  Content Fragment elements/variations by its name

ContentElement title = fragment.getElement("title");
ContentVariation mobileAppVariation = title.getVariation("mobile-app");

Programmatically Accessing Content:

String content = element.getContent();
String contentType = element.getContentType();

Programmatically Modifying Content Fragment content
element.setContent("Content", "text/plain")

Programmatically Modifying Content Fragment metadata
void setMetaData(String name, Object value) throws ContentFragmetException

YouTube demo videos for Content Fragments:
         AEM 6.3 Content Fragments Basics
         Content Fragments AEM
         View Content fragment output in aem

Thursday, 22 June 2017

AEM Content Fragment output as JSON

AEM Content Fragments can be accessed through JSON file URL's. This helps to verify the data while authoring.

To ensure the JSON format is enabled follow below steps:

To enable the content fragment JSON, we need to enable /system/console/configurations > AEM Content Service Feature Flag > (Select) Enable AEM Content Services check box.


YouTube demo videos for Content Fragments:
         AEM 6.3 Content Fragments Basics
         Content Fragments AEM
         View Content fragment output in aem

Say we have created 'this-is-my-frag' Content Fragment,

We can see the complete content using infinity json as url.
http://localhost:4502/content/dam/this-is-my-frag.infinity.json

If we want to generate its output as caas way below url helps.
http://localhost:4502/content/dam/this-is-my-frag/_jcr_content.caas.json

{
    "_children": [{
        "name": "jcr:content",
        "title": "This is my frag",
        "path": "/content/dam/this-is-my-frag/jcr:content",
        "type": "dam:AssetContent",
        "href": "http://localhost:4502/content/dam/this-is-my-frag/_jcr_content.caas.json"
    }]
}

Now when we load the children from above _jcr_content.caas.json

{
    "title": "This is my frag",
    "dam:assetState": "processed",
    "description": "Hello there",
    "contentFragment": true,
    "lastFragmentSave": "Wed Jun 21 2017 15:29:39 GMT+0530",
    "dam:relativePath": "this-is-my-frag",
    "_children": [{
        "name": "renditions",
        "path": "/content/dam/this-is-my-frag/jcr:content/renditions",
        "type": "nt:folder",
        "href": "http://localhost:4502/content/dam/this-is-my-frag/_jcr_content/renditions.caas.json"
    }, {
        "name": "related",
        "path": "/content/dam/this-is-my-frag/jcr:content/related",
        "type": "nt:unstructured",
        "href": "http://localhost:4502/content/dam/this-is-my-frag/_jcr_content/related.caas.json"
    }, {
        "name": "associated",
        "path": "/content/dam/this-is-my-frag/jcr:content/associated",
        "type": "sling/collection",
        "href": "http://localhost:4502/content/dam/this-is-my-frag/_jcr_content/associated.caas.json"
    }, {
        "name": "metadata",
        "path": "/content/dam/this-is-my-frag/jcr:content/metadata",
        "type": "nt:unstructured",
        "href": "http://localhost:4502/content/dam/this-is-my-frag/_jcr_content/metadata.caas.json"
    }, {
        "name": "model",
        "title": "Simple Fragment",
        "path": "/content/dam/this-is-my-frag/jcr:content/model",
        "type": "nt:unstructured",
        "href": "http://localhost:4502/content/dam/this-is-my-frag/_jcr_content/model.caas.json"
    }]
}

Now we can iterate through the children in above json and get corresponding renditions, related, associated, metadata, model

For eg: model gives below json
{
    "title": "Simple Fragment",
    "version": 2,
    "description": "A simple fragment, containing one single element and no predefined variations",
    "precreateElements": true,
    "_children": [{
        "name": "elements",
        "path": "/content/dam/this-is-my-frag/jcr:content/model/elements",
        "type": "nt:unstructured",
        "href": "http://localhost:4502/content/dam/this-is-my-frag/_jcr_content/model/elements.caas.json"
    }, {
        "name": "variations",
        "path": "/content/dam/this-is-my-frag/jcr:content/model/variations",
        "type": "nt:unstructured",
        "href": "http://localhost:4502/content/dam/this-is-my-frag/_jcr_content/model/variations.caas.json"
    }]
}

where the variations from above link loads

{
    "_children": [{
        "name": "variation2",
        "title": "variation2",
        "path": "/content/dam/this-is-my-frag/jcr:content/model/variations/variation2",
        "type": "nt:unstructured",
        "href": "http://localhost:4502/content/dam/this-is-my-frag/_jcr_content/model/variations/variation2.caas.json"
    }]
}

This way we can iterate through the content fragment JSON.

https://www.youtube.com/channel/UCbDTGaDneAbj_RCX27VE4cA/videos



Subscribe Our YouTube Channel Here.


Related Posts

AEM Leading to head less CMS?
AEM Content Fragment output as JSON
AEM 6.3 Content Fragments Basics
How to create a Content Fragment? step by step tutorial
Create & Access the content fragment programmatically


AEM 6.3 Content Fragments Basics


AEM 6.3 Supports Content Fragments to deliver content as a service.
Experience Fragments enables Experience-as-a-Service, where the CMS controls partial-page rendering, or Hybrid CMS, solutions that let you push your content to any channel — just as headless systems do — using a delivery tier that connects all those channels and shares data between them.

What is a content fragment?

  • Contains one or more Content Elements,
  • Content can have one or more  Variations.
  • Content fragment can be created based on templates which define the structure.
  • Content fragments are a type of new assets.
  • Content Fragment use existing Assets functionality & fully integrated with assets.
  • Content Fragments are well tied with Translation workflows, metadata schema.
         YouTube demo videos for Content Fragments:
         AEM 6.3 Content Fragments Basics
         Content Fragments AEM
         View Content fragment output in aem

A content fragment groups renditions, related items, associated items, metadata, model, elements, variations etc in a single Content.



Can we add a Content Fragment to a page?

Yes it can be added to a page using default content fragment component as other components.

Which is the API service for Content Fragments?
Latest AEM provides server side API com.adobe.cq.dam.cfm to programmatically interact with Content Fragments.



Related Posts

AEM Leading to head less CMS?
AEM Content Fragment output as JSON
AEM 6.3 Content Fragments Basics
How to create a Content Fragment? step by step tutorial
Create & Access the content fragment programmatically







AEM Leading to head less CMS?

Headless 
Now a days many goes with headless CMS. Here the content capabilities of a CMS are not used for rendering; the rendering output could be through any channel like websites, print, campaign or mobile apps. From Beginning AEM's one of the core module Apache Sling, allows to access the contents of the JCR through HTTP requests.

The DefaultGetServlet helps to render content in JSON format by using the json extension.
For eg: /content/site/en/page.infinity.json

In addition to the OOTB features, one can create Sling Servlet to expose content which ever format we want.



The latest AEM features:
AEM 6.3 is built with Content as a Service (CaaS) feature. Now AEM provides editor an aggregated view of content within the JCR called Content Fragments. This content can be assets, content fragments or pages, intended for external consumption.

Caas  = > content as a service
The CaaS way suggest that a CMS should only be used for managing content, not for controlling its presentation.

Caas features

  • The CMS just hosts the content.
  • Content structure here is highly customizable, which can be managed through a web framework.
  • The content can be available through RESTful API in formats like JSON/xml.

Advantages of Caas

  • Presentation is decoupled from content. The delivery channel could be websites, campaigns, print, mobile apps, and other devices and channels.
  • Here content supports different variations which could be varying for devices. Content author is not aware of the display part of the system.
  • Here the data is content centric and not page centric.


Some use cases of CaaS (scenarios when a content fragment to be used?)

Multi-channel approach: The same content can be used to render for websites or mobile which makes the system more flexible.
Mobile apps content backend: Real world want more latest content on mobile devices. This approach helps for pulling data from a live content system supporte by Caas.
MVC Front end support : Angular, ReactJS can be used to provide rich front end. Also the CMS front end has restrictions based on the architecture of CMS. Thus Caas model supports any MVC front end frame work.
Easy integration with existing services : There are cases where we need to use/ pull existing content to new system. Using the Caas API this is quite easy.

YouTube demo videos for Content Fragments:
AEM 6.3 Content Fragments Basics
Content Fragments AEM
View Content fragment output in aem

Related Posts

AEM Leading to head less CMS?
AEM Content Fragment output as JSON
AEM 6.3 Content Fragments Basics
How to create a Content Fragment? step by step tutorial
Create & Access the content fragment programmatically