Archive for July, 2015

Add a touch-optimized dialog (for the YouTube component)

In this short session, you will learn how to add a touch-optimized dialog for the YouTube component. As I mentioned earlier, a touch-optimized GUI is designed for using in hand-held devices, such as iPad, tablets, and so on.

(I have uploaded the package in GitHub. You should use:

Double-click the component that we developed. The dialog you see is called the Classic dialog. It should ideally come up only if you are in the Classic mode. Right now, you are on Touch-Optimized mode; the Classic dialog comes up here, because we have not created a Touch-Optimized dialog.

Let us start working by logging into CRXDE Lite. We will follow the same strategy we used before. Copy and paste a dialog that is already created, and then customize it.

  1. Go to /libs/wcm/foundation/components/title/.
  2. Copy cq:dialog node from there.
  3. Paste the node under the YouTube component.
  4. Expand the node.
    We need only title node here. (We want users to enter only one property; that’s the url.)
  5. Delete the other node.
  6. Change the following properties to match them with what we entered for Classic dialog:
    FieldDescription: Enter YouTube URL
    FieldLabel: YouTube URL
  7. Now refresh the page.
  8. Select the component and select Edit.
    Note that the dialog has changed.
  9. Now, go to the Classic view and see the dialog.
    You see the classic dialog.

To summarize, cq:dialog is used for Touch-Optimized dialogs. You add various fields to it depending on the requirement. Fields are inherited from granite/ui/components/foundation/form/textfield.

That’s about this session. See you soon.

Get data from a dialog using Sightly (Get a custom URL for the YouTube component)

In this session, you will see how to update the YouTube component to capture the URL entered by an author in the dialog. (I have uploaded the sample code in GitHub.)

We have accomplished the following so far.

  1. Created a YouTube component that will add a specific YouTube video to the page.
  2. Created a dialog where the author can enter a different URL.

The requirement was to update the video using the URL entered by the author.

Let us start. We will create a JavaScript file named url.js to write our logic.

  1. Create a js file url.js.
  2. Copy and paste the following code:
use(function () {
var CONST = {
PROP_TITLE: "jcr:title",}
var url = {};
// The url entered in the dialog
url.text =[CONST.PROP_TITLE]
if (url.text ==null)
 url.text = "";
// Adding the constants to the exposed API
return url;

Let us go through the code line-by-line. It creates a JavaScript function. It creates a constant PROP_TITLE and assigns jcr:title to it. It is a very important property. Let us take a look at the JCR properties after you add a value to the component’s dialog.

Go to content > aem-company > jcr: content > content > youtube_1.

Note that jcr:title property captures the URL entered in the dialog. We have entered the name of the dialog as ./title and that’s the reason its value is captured as jcr:title. The code creates a variable url. Added a text property to the URL and it captures[CONST.PROP_TITLE], basically the URL entered by the authors. Then the code checks if the url.text property is null. It’s null when there is no value entered in the dialog. In that case, we are assigning a default value. We are returning url as a constant.

Now let us change the code that we wrote in the YouTube.html to use the script.  Copy and paste the following code to YouTube.html.

<div data-sly-use.url="url.js" style="overflow: hidden;">
     <iframe width="600" height="510" src="${url.text}" frameborder="0" allowfullscreen></iframe>

The data-sly-use attribute assigns the return value of url.js to the url variable. We extract the url from the url property using ${url.text}. See how simple it is.

Now let me give you another URL to test: (This is another YouTube video that I shared some time back. It has a title, AEM Authors, Templates, Components.)

  1. Drag and drop the YouTube component to the web page.
  2. Select it and select Edit.
  3. Enter the URL that I gave above.
  4. Select OK.

Note that the video is updated.

There are lots of pitfalls in the component. At the first place, it does not check if the entered string is a URL or not. Also, no need to display a video at the first instance, and so on. The intention was to show you how to capture a user input from the dialog; and we have succeeded.
See you in the next session.

Create Adobe Experience Manager dialogs (Add a dialog to the YouTube component)

In this short session, we will see how to create AEM dialogs. This is primarily an overview session about AEM dialogs.
I have shared the package in GitHub.

AEM dialogs are used to enter information to a component. For example, if you open a page that I showed here and double-click the Title element, a dialog appear. You can enter certain information, such as Title, Link, and so on. Just to demo, let me change the title to my name, Sunil, and see. You could see that the title of the page is changed.

Dialog you just saw is a touch-optimized dialog – it means this dialog is optimized to view in various devices, such as phones and tablets. AEM used to have a different dialog. Let us see it. Go to the Classic view. Double-click the title page. I hope you noticed the difference. This dialog is used in Desktops. Most of your users may want to use touch-optimized dialogs that enable them to work on hand-held devices. And of course, that’s the future.

I will first introduce you to the latter – the dialog that’s not touch-optimized – the Classic dialog. We will see how to create a dialog for the YouTube component. We have seen the component adds a YouTube video to the page. Author wants to change the URL of the YouTube video. So, the requirement is to provide them with a dialog that allows them to enter a URL.

Delete the dialog that you created earlier. Let us copy a dialog from an existing component. Then, we will refine it based on our requirement. This is always a good strategy, because we are starting with something tried and tested. We can use the dialog of a component named, title.

  1. Delete the dialog you already created.
  2. Copy the dialog from /libs/wcm/foundation/components/title/dialog.
  3. Paste dialog underneath youtube.
  4. Remove /youtube/dialog/items/title/type.
  5. Select title and update it.
    Field Label: YouTube URL
    Field Description: Enter YouTube URL.
    (This is an instruction for authors.)
  6. Don’t change the name.
    xtype defines what exactly the field is. It’s a text field.

Now let us see how the dialog appears in the web page.

  1. Open the web page.
  2. Double-click.
  3. See that the dialog appears.

Let us wind up the session here. Remember, we need to add the logic to capture URL entered here to update the web page. We will see how to accomplish that in the next session.

See you all soon!!

Create your first Sightly component (YouTube component !!!)

In this session, you will learn how to create an AEM component. You have learned that an AEM component is used to display an information in a certain way. You will use Sightly to create the component.

We will call the component as YouTube component. When you drag and drop the component to a web page, it will display a YouTube video – specifically, a YouTube video I uploaded as a part of this learning series.

So, let us start:

  1. Login to CRXDELite.
  2. Navigate to the directory stucure we have created earlier.
  3. Go inside the Component folder.
  4. Right-click and select Create Component.
  5. Enter the following:
    Label: youtube
    Title: DisplayYouTube
    Description: This component is used to display the YouTube video
    Group: AEM Company
  6. Click Next and Next.
  7. Enter Allowed Parent as */parsys
  8. Click Next and Click OK.
  9. Now, rename youtube.jsp to youtube.html. (By deafault, CRXDELite creates a JSP component. I have mentioned earlier that we will create the component using Sightly. That’s why we renamed the extension to html.)
  10. Add the following code:
    <div style="overflow: hidden;">
            <iframe width="600" height="510" src="" frameborder="0" allowfullscreen></iframe>

    (I have taken the embedded code directly from YouTube. Then changed the width and height. I wrapped it around a div element and added the overflow attribute to remove extra space.)

  11. Create a dialog now. We are not going to do anything with the dialog. However, it’s needed for a newly created component to appear in the sidekick.
  12. Right click YouTube, select Create > Create Dialog.
  13. Enter title as YouTube and select OK.

The component is created now. Let us enable it.

  1. Open the web page you created.
  2. Go to the Design View.
  3. Enable the Component Group; that is, AEM Company.
  4. Go to the Edit view.
  5. From the component group, drag and drop the component to your page.
  6. See the way YouTube video appears.

That’s it. We will see how to customize component shortly.

As usual, I have uploaded the code to my GitHib. Please feel free to use it.