Showing posts with label Content Fragment. Show all posts
Showing posts with label Content Fragment. Show all posts

Thursday, 7 February 2019

How can we create a custom datatype in the content fragment models in AEM


For majority of the use cases, the given content fragment datatypes will satisfy any use cases. But still if we need to extend the data type functionality further, below approach can be tried.

To start with, let us understand the data type structure in AEM.

Content Fragment model data types are configured at:
/libs/settings/dam/cfm/models/formbuilderconfig/datatypes/items/enumeration

and each dataype has properties as below,
  • fieldIcon
  • fiedPropResourceType
  • fieldProperties
  • fieldResourceType
  • fieldTitle
  • fieldViewResourceType
  • renderType
  • valueType

There are some additional fields which are specific to the fields.

Now, if you observe closely,
  • fiedPropResourceType having string value 'dam/cfm/models/editor/components/datatypes/field'
  • fieldIcon, fiedTitle -are data type naming specific.
  • fieldResourceType, renderType, valueType - are behavior specific to the data types.
All the fieldResourceType values are referred from /libs/granite/ui/components/coral/foundation, /libs/dam/cfm/models/editor/components, /libs/dam/cfm/admin/components etc.

Below given a screenshot of default Boolean data type properties.


 
Custom?
Now say if you need to create a custom data type for the content fragment, you can create a project specific structure of the data type referring the default one, the same way we extend the components.

If there is any other way to implement this, please let me know through the comments.

Tuesday, 18 December 2018

AMP with AEM - Demonstrating the ability of Content Fragments in AEM


AMP integration with AEM - CaaS Model(Content as a service) demo 

I was receiving requests for writing sample code to showcase Third party AMP page which retrieve data from AEM (Content as a service).

What is AMP?

The AMP Project is an open-source Google-run website publishing technology initiative aiming to make the web better for all. The project enables the creation of websites and ads that are consistently fast, beautiful and high-performing across devices and distribution platforms. More details on https://www.ampproject.org/

How can I develop AMP websites?

You need to refer the above url for implementing AMP Projects, which has detailed information about syntax of AMP.

AMP integration with AEM

Step 1: To work with AMP and AEM, create an AMP file as shown below and deploy it on any server.
(You can refer PWA implementation & deployment article for the same: Set-up PWA running environment).

A sample AMP Structure is given below.

Save below file as 'Sample_AMP.html'


<!doctype html>
<html ⚡>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width,minimum-scale=1,initial-scale=1">
  <title>AMP demo with AEM</title>
  <link rel="canonical" href="index.html" />
  <script async src="https://cdn.ampproject.org/v0.js"></script>
  <script async custom-element="amp-list" src="https://cdn.ampproject.org/v0/amp-list-0.1.js"></script>
  <script async custom-template="amp-mustache" src="https://cdn.ampproject.org/v0/amp-mustache-0.2.js"></script>
  <style amp-boilerplate>body{-webkit-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-moz-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-ms-animation:-amp-start 8s steps(1,end) 0s 1 normal both;animation:-amp-start 8s steps(1,end) 0s 1 normal both}@-webkit-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-moz-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-ms-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-o-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}</style>
  <noscript>
         <style amp-boilerplate>body{-webkit-animation:none;-moz-animation:none;-ms-animation:none;animation:none}</style>
  </noscript>
</head>
<body>
<amp-list width="auto"
  height="100"
  layout="fixed-height" src="test.json">
  <template type="amp-mustache">
    <div class="url-entry">
      <a href="{{url}}">{{title}}</a>
    </div>
  </template>
</amp-list> 
</body>
</html>

It takes a JSON input file(src="test.json") and publish data on page.


Step 2: Author a content fragment in AEM which has JSON format as below.
Follow this link for Creating & Authoring Content Fragments:  Create & Author Content Fragments in AEM

{
 "items": [
   {
     "title": "AMP YouTube",
     "url": "https://www.youtube.com/"
   },
   {
     "title": "AMPproject.org",
     "url": "https://www.ampproject.org/"
   },
   {
     "title": "AEM Tutorial Blog",
     "url": "http://aem-cq-tutorials.blogspot.com/"
   },
   {
     "title": "Solr with AEM Totorial",
     "url": "http://aemsolr.blogspot.in/"
   }
 ]
}


Step 3: Now, update the 'Sample_AMP.html' for src="test.json"with publish url of content fragment authored page


Step 4: Ensure CORS is enabled in AEM. (Confused? Refer https://aem-cq-tutorials.blogspot.com/2018/12/integrate-pwa-aem-and-retrieve-aem.html to updated CORS)

Step 5: Now invoke the AMP file, from server, you can see that data is appearing as shown below.

AMP with AEM - click on it to see big

*(I haven't done styling just Functionality is tested).

Notes:
AMP - uses specific tags and syntax which needs to be validated after each change in code. You can use online AMP validator(https://validator.ampproject.org/) for this purpose.

Related Posts

>Step 1: Set-up PWA running environment
>Step 2: How to create & Deploy a Progressive Web Application
>Step 3: Create & Author Content Fragments in AEM
>Step 4: Integrate PWA & AEM and retrieve the AEM content from PWA.


AEM Content Fragments Demo: Integrate AMP with AEM
 

Friday, 14 December 2018

Create & Author Content Fragments in AEM

Previous post on this topic
How to create & Deploy a Progressive Web Application


Login to AEM, go to Assets > Files.
Let us create a folder now called 'My Samples' by clicking the create button.
Create CF Folder - click on it to see it big

Now go inside the folder and click on create > Content Fragment.

Then Select the Simple Fragment template. Enter title and description and then click on create.



Create Content Fragment AEM


In next dialog click on open and edit content fragment as shown below.

[Author CF]


To access the content fragment, we need to author it on a page. Let us author it on a sample we-retail page.

Now go to sites> we-retail > us >en > Men, open it for editing.

From component browser, drag and drop 'Content Fragment' component on the page.

[Author Content Fragment AEM 6.2 onwards


Click on Configure and add the newly created Content Fragment and save it.

[Authoring and landing]


We have the authored Content Fragment now. We can access it over the JSON Exporter API by invoking the '.model.json' in author instance, For me it was below URL.

http://localhost:4502/content/we-retail/us/en/men/jcr:content/root/responsivegrid/contentfragment.model.json

Note: This URL needs to be updated in file "retrieve_content_fragment.js" at line '$("button").click(function(){ $.ajax({url:'

The sample output is given below.


[AEM 6.4 Content Fragment Output]


Now Publish the page where Content Fragment is authored. So that all data is available in AEM Publish

Demo


Next post:
Integrate PWA & AEM and retrieve the AEM content from PWA.

AEM With Progressive Web Apps - Demonstrating the ability of Content Fragments in AEM - Display AEM Content to Third Party Applications

AEM - Getting more headless

We all know that AEM is the leader in CMS-world ; day by day new features are getting added as part of new version upgrades. Recently Adobe released AEM 6.5 version with lot more features.

From previous few AEM versions support head-less capability, which means AEM Content can be delivered to multi channels or third party applications.

AEM Provides headless capability through Content Fragments and Experience Fragments. 
In this post we will show a use case of , how to use content fragments with external applications

Click on image to see it big



In this tutorial we will see,
  • How to create & Deploy a Progressive Web Application - PWA(Including 'what is PWA', 'how do we run a PWA')?
  • Create Content Fragments in AEM.
  • Integrate PWA & AEM and retrieve the AEM content from PWA.


Let us first understand what is PWA?

In my previous post I have given an overview of PWA

Progressive Web Application - PWA:
This is an application which behaves like a native application and developed using modern web technologies. This application supports offline features(using service worker & Web App Manifest) when no internet connection and are extremely fast & engaging.

  • PWA is an idea proposed by Google developers.
  • A PWA is mainly dependent on Service Worker and Manifest files.

What is a Service Worker?
They are scripts that stand between your web application and your network

What is a Web App Manifest?

Web App Manifest is a JSON file with meta-information about the site.

PWA can be developed using technologies : Angular, React , Vue


PWA Features:

1. Responsive

2. Push Notification.

3. Offline Support.

4. Fast and efficient.

5. Not served through app store.

6. relatively cheaper than developing native apps

7. Does not require installation

Follow below sections to continue with this tutorial to learn integrating AEM With Progressive Web Apps

>Step 1: Set-up PWA running environment
>Step 2: How to create & Deploy a Progressive Web Application
>Step 3: Create & Author Content Fragments in AEM
>Step 4: Integrate PWA & AEM and retrieve the AEM content from PWA.


Demo Videos:


AEM Content Fragments Demo Part 1: PWA With AEM 



AEM Content Fragments Demo Part 2: PWA Running Environment setup

AEM Content Fragments Demo Part 3: Create & Deploy a Progressive Web Application

AEM Content Fragments Demo Part 4: Create & Author Content Fragments

AEM Content Fragments Demo Part 5 : Integrate AEM with PWA

Wednesday, 12 December 2018

Steps to Create custom Content Fragment Templates in AEM 6.4

Hope you have gone through the basics of Content Fragments in AEM.
Create Content Fragments : Step By Step Tutorial

AEM 6.4 Content Fragment

[This tutorial works for versions AEM 6.2, AEM 6.3, AEM 6.4]

Generally AEM provides default content fragments template called 'Simple Fragment' [at location: /libs/settings/dam/cfm/templates]. But we may need to customize or create new templates based on our needs.

Here I will explain how we can create custom content fragment templates.

Where to create custom content fragment templates?


There are multiple places we can create custom content fragment templates.

  • Config: When we work with folder specific templates, use this location.
  • Apps: Usually general purpose templates are created here.


Content Fragment Templates Path


Let us create a template under /apps for general purpose use.

Steps
  • Traverse to /apps/settings/dam inside CRXDE lite.
  • Create a node of type cq:Page and name it 'cfm'
  • Under the newly created cfm node, create another node of type cq:Page and name it 'templates'.
  • Under templates node create a node of type cq:PageContent and name it 'jcr:content'.
  • Under jcr:content create a new boolean property called 'mergeList' with value 'true', this step ensures our new template is available in addition to /lib content fragment templates for authoring.
  • Now do 'Save All'.
Our crx looks like this now

Custom Content Fragment creation



We have the structure ready now, we will add properties for the template now by referring the /lib/ 'Simple Fragment' template.

  • Traverse to /libs/settings/dam/cfm/templates and copy 'simple' node.
  • Paste it on our structure under /apps/settings/dam/cfm/templates.
  • Now do a 'Save All'.

We now have below structure in crx.




We have a template similar to 'Simple Fragment' now. Let us customize the template for our need.

We will create title, description as elements and 2 variations for desktop and mobile.

Let us start by renaming 'simple' node to 'custom'

  • Select “jcr:content” under 'custom', Update the value of 'jcr:description' to 'A custom project specific fragment'.
  • Update value of 'jcr:title' to 'Custom Fragment'
  • Now rename 'main' under elements to 'title', update its 'jcr:title' to 'Title' and name to 'title'
  • Next create a new element – description by copying the  main and renaming. Update the 'jcr:title' to 'Description' and name to 'description'.
  • Now select node 'jcr:content' under node 'custom' and create a new node of type 'nt:unstructured' and name it 'variations'.
  • Create a new node for 'desktop' of type nt:unstructured under variations; add properties 'jcr:title' 'Desktop' and name 'desktop'.
  • Create a new node for 'mobile' of type nt:unstructured under variations; add properties 'jcr:title' 'Mobile' and name 'mobile'.
  • Now click on 'Save All'.

A new custom template is created now, which is ready for authoring.


Authoring Custom Content Fragment

Now go to AEM Assets >Files , click on 'Create' from top right hand corner and select 'Content Fragment'.
Here you can see the 'Custom Fragment'


Custom Fragment AEM 6.4



Select the 'Custom Fragment' and click 'next'.

Enter the values for title, description and click 'Create' then click on 'Open'.

Here you can see that a new Content Fragment is available with 'title', 'description'.
Similarly we can see that variations for 'desktop' and mobile also available for authoring.

In my upcoming blog, I will give a walkthrough on using Content Fragment with Progressive Web Applications.

Please dont forget to subscribe the blog.

Read More:

https://aem-cq-tutorials.blogspot.com/2018/06/create-content-service-end-point-in-aem.html

https://aem-cq-tutorials.blogspot.com/2018/05/aem-64-content-fragment-output-as-json.html




Monday, 4 June 2018

Create Content Service End point in AEM 6.4

Content Services & its use

Content Services enable the creation of Page-based HTTP end-points. This end points helps to render the content to a normalized JSON format.

How to configure & access the content services in AEM 6.4?
We need to configure content service end points when ever we need to export a Content Fragment data to external applications(Like Single Page Application or mobile app etc). Let us see how it can be done. The end point pages are not to be accessed as HTML pages, they just export the content in JSON Format.

We have created multi variation Content Fragments following our previous blog Create Content Fragments : Step By Step Tutorial.

Say we have master, mobile , tab variations as shown below.
[Click om images to see it big]


[Mobile & Tab Content Fragment]


Go to Sites> We-retail, click on 'Create' > 'Page'
Enter details as below and click on create. A new page will be created. (/content/we-retail/content-service-for-sample-fragment.html)




Open the page and author the content fragment in this page(Steps are explained in my previous post).




As you see, I have authored master, variation1(Mobile), Variation 2 (Tab) in the same page.

Now go to the page url and append '.model.json' to invoke JSON exporter. (In my case: content-service-for-sample-fragment.model.json). You can see the JSON with all variations included.



[JSON portion of Content Fragment for Mobile]



[JSON format for tablet]



From this JSON, we can iterate over the content fragments section and by checking for the variation, we can render items across various channels.

Remember I have authored the Content Fragment utilizing an existing we-retail template. So the JSON will have all related items like header , footer etc. In real projects, create a stand alone template and then create a page from this.

Related posts:
Create Content Fragments : Step By Step Tutorial
Content Fragment out put as JSON 

 

Thursday, 31 May 2018

AEM 6.4 Content Fragment output as JSON

AEM Content Fragments can be accessed through JSON file URL's.

Create Content Fragments : Step By Step Tutorial

Why we need JSON Formats?
Content Fragments are not just for web pages. A Content Fragment is made available to external applications through JSON format delivery methods. These applications could be,
  • Single Page Applications
  • Native Mobile Applications
  • other channels and touch-points external to AEM
[Click on image to see it big]





AEM 6.4 core components having the capability to export its data to JSON format. This structured content can then be used to deliver to cross channels other than AEM pages. 

Difference between Content Fragment & Experience Fragment
Major difference between Content Fragment & Experience Fragment is that Content Fragment is pure content, without design and layout, but Experience Fragments are fully laid out content - a fragment/portion of a web page.

There are 2 types of content fragments

Simple fragments : Which does not have any predefined structure(only text, and images). Simple Fragment template is the supporting element for this.

Fragments that contain structured content: This is based on a content fragment model. This model will give defined structure.

How do we generate JSON format of a Content Fragment?

AEM 6.4 version also supports JSON Exporter with Content Fragment Core Components. Using this AEM JSON exporter, we can deliver the contents of an AEM page in JSON data model format. This can then be consumed by any third party applications other than AEM.

JSON Exporter is supported by suffixing a url with '.model.json'

Access JSON Format of a Content Fragment

Say we have created 'My Simple Fragment(my-simple-fragment)' Content Fragment,

We can see the complete content using url,
http://localhost:4502/content/dam/my-simple-fragment/_jcr_content/model.json


As you see the output

    {
        "jcr:primaryType": "nt:unstructured",
        "jcr:title": "Simple Fragment",
        "version": 2,
        "jcr:description": "A simple fragment, containing one single element and no predefined variations",
        "precreateElements": true
    }

   
Accessing the JSON output of a Content Fragment authored on a page.


Step1: Access the page JSON

Now I have authored my previously created 'My Simple Fragment(my-simple-fragment)' in We-retail site.(/content/we-retail/language-masters/en/men.html)

Its JSON output can be access through url,
http://localhost:4502/content/we-retail/language-masters/en/men.model.json

Step2: Access the Content Fragment JSON
We can see the content fragment in this page as shown.





To get the authored 'Content Fragment JSON', access the '.model.json' url of the content fragment as below,

http://localhost:4502/content/we-retail/language-masters/en/men/jcr:content/root/responsivegrid/contentfragment_1655772226.model.json

As you see the JSON will have all elements including variations created/authored.





Create Content Fragments : Step By Step Tutorial

Wednesday, 30 May 2018

How to create a Content Fragment in AEM 6.4? Step by step tutorial

Content Fragment helps to author content without creating a Page. The advantage with Content Fragment is that same content can be shared across various channels without worrying about the display part.

What type of data, 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.

Steps to create Content Fragments

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

[click on images to see it big]
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. Click on Next





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.



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



Edit options for a content fragment is quiet flexible, through which we can update the textual content, create variations, add / edit metadata etc.



Through 'Create variation' we can create different version of content based on our requirement. These variations are used across different channels.



Now the variation created  will have below action items.



Clicking the 'folder' icon provides us the option to associate content with 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:

Download a 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.



Deleting a Content Fragment

In the Assets console navigate to the location of the content fragment, Select the fragment and click on delete from tool bar menu.



In the upcoming posts I will be explaining authoring and utilization of Content Fragments.

Read about Content Services in AEM 6.4 and demo

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