Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.
SOLVED

how to display "last updated on" in my AEM page?

Avatar

Level 2

so I  wanna display the "last updated on" base on the changes made to the content (excluding header/footer).

Any ideas how this can be done? on our AEM, the header and footer is a separate component and I should like to display the "last updated on" on the footer.

I've searched the net but didn't see anything useful.

Thanks!

1 Accepted Solution

Avatar

Correct answer by
Level 5

Hi,

What do you mean by above statement. Do you want to show it on footer html ?

If you are trying to read the last modified date of footer node. Just add the below code in your footer component:

Last Updated on ${'dd-MM-yyyy' @ format=properties['jcr:lastModified']}
(or)

Last Updated on ${'dd-MM-yyyy HH:mm' @ format=properties['jcr:lastModified'], timezone='GMT+05:30'}

Go through this link as well : htl-spec/SPECIFICATION.md at master · Adobe-Marketing-Cloud/htl-spec · GitHub

Update:

The above code works on 6.3 but not on 6.2 .

You can do as below:

package com.project;

import java.text.SimpleDateFormat;

import java.util.Calendar;

import com.adobe.cq.sightly.WCMUsePojo;

public class DateFormatter extends WCMUsePojo {

    private String formattedDate;

    @Override

    public void activate() {

    Calendar date  = get("date", Calendar.class);

    String format =  get("format",String.class);

    SimpleDateFormat formatter = new SimpleDateFormat(format);

    formattedDate = formatter.format(date.getTime());

    }   

    public String getFormattedDate() {

        return formattedDate;

    }

}

<sly data-sly-use.date="${'com.project.DateFormatter' @ date=properties['jcr:lastModified'],format='dd/MM/yyyy'}">

    ${date.formattedDate}

</sly>

View solution in original post

5 Replies

Avatar

Correct answer by
Level 5

Hi,

What do you mean by above statement. Do you want to show it on footer html ?

If you are trying to read the last modified date of footer node. Just add the below code in your footer component:

Last Updated on ${'dd-MM-yyyy' @ format=properties['jcr:lastModified']}
(or)

Last Updated on ${'dd-MM-yyyy HH:mm' @ format=properties['jcr:lastModified'], timezone='GMT+05:30'}

Go through this link as well : htl-spec/SPECIFICATION.md at master · Adobe-Marketing-Cloud/htl-spec · GitHub

Update:

The above code works on 6.3 but not on 6.2 .

You can do as below:

package com.project;

import java.text.SimpleDateFormat;

import java.util.Calendar;

import com.adobe.cq.sightly.WCMUsePojo;

public class DateFormatter extends WCMUsePojo {

    private String formattedDate;

    @Override

    public void activate() {

    Calendar date  = get("date", Calendar.class);

    String format =  get("format",String.class);

    SimpleDateFormat formatter = new SimpleDateFormat(format);

    formattedDate = formatter.format(date.getTime());

    }   

    public String getFormattedDate() {

        return formattedDate;

    }

}

<sly data-sly-use.date="${'com.project.DateFormatter' @ date=properties['jcr:lastModified'],format='dd/MM/yyyy'}">

    ${date.formattedDate}

</sly>

Avatar

Level 4

Hi Susheel,

I want to display the last modified date of page in which i put this footer node.Please let me know

Avatar

Level 10

You would implement a HTL component using Java WCMUSEPOJO and obtain this node property using Java code. Then display the value via HTL - as explained the correct response of this thread.

Avatar

Level 4

How to obtain node property in java? The above code displays the footer node last modified date. But i need the page last modified date

Avatar

Level 6

Hi,

You can use Node Property like below.

String nodePath = "/content/community-components/en/comments/jcr:content/content/title";

try

{

Node node = null;

NodeIterator nodes =null;

String result="";

resource = slingRequest.getResourceResolver().getResource(nodePath);

   if(resource != null)

  {

  node = resource.adaptTo(Node.class);

  

   if(node.hasProperty("jcr:lastModifiedBy"))

  {

  result=node.getProperty("jcr:lastModifiedBy").getValue().getString();

  out.print(result);

  

  }

  }

}

catch(Exception e)

{

out.print(e);

}

Regards

Manikantha R