Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn More

View all

Sign in to view all badges

Reading date property using sightly

Avatar

Avatar
Validate 1
MVP
Runal_Trivedi
MVP

Likes

45 likes

Total Posts

153 posts

Correct Reply

68 solutions
Top badges earned
Validate 1
Ignite 1
Give Back 5
Give Back 3
Give Back 10
View profile

Avatar
Validate 1
MVP
Runal_Trivedi
MVP

Likes

45 likes

Total Posts

153 posts

Correct Reply

68 solutions
Top badges earned
Validate 1
Ignite 1
Give Back 5
Give Back 3
Give Back 10
View profile
Runal_Trivedi
MVP

15-10-2015

Hi,

I was trying to read date property using sightly but it wont output anything. Below is the snippet that I used but it will always come as blank:

Date Modified - ${pageProperties.cq:lastModified}

I also tried possibly context options but in vain.

I am trying to avoid Java Helper class route for simply reading one property.

Anyone faced that error before or any solutions to read date property apart from using java helper class?

Thanks,

Runal

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar
Give Back 50
Employee
Feike_Visser1
Employee

Likes

247 likes

Total Posts

970 posts

Correct Reply

221 solutions
Top badges earned
Give Back 50
Give Back 5
Give Back 3
Give Back 25
Give Back 10
View profile

Avatar
Give Back 50
Employee
Feike_Visser1
Employee

Likes

247 likes

Total Posts

970 posts

Correct Reply

221 solutions
Top badges earned
Give Back 50
Give Back 5
Give Back 3
Give Back 25
Give Back 10
View profile
Feike_Visser1
Employee

15-10-2015

Here an example how to do date-formatting, done via Sling-models

Sightly: <div data-sly-call="${ dateFormat @ date=currentPage.lastModified, dateFormat='dd/MM/yyyy' }"> </div> <template data-sly-template.dateFormat="${ @ date, dateFormat }"> <div data-sly-use.formatter="${'com.yourproject.DateFormatting' @ date=date,dateFormat=dateFormat}"> Formatted value : ${formatter.formattedValue} </div> </template>
Java: @Model(adaptables=SlingHttpServletRequest.class) public class DateFormatting { @Inject // injected as parameter private Calendar date; @Inject // injected as parameter private String dateFormat; public String formattedValue; @PostConstruct protected void init() { SimpleDateFormat formatter = new SimpleDateFormat(dateFormat); formattedValue = formatter.format(date.getTime()); } }

Answers (6)

Answers (6)

Avatar

Avatar
Give Back 50
Employee
Feike_Visser1
Employee

Likes

247 likes

Total Posts

970 posts

Correct Reply

221 solutions
Top badges earned
Give Back 50
Give Back 5
Give Back 3
Give Back 25
Give Back 10
View profile

Avatar
Give Back 50
Employee
Feike_Visser1
Employee

Likes

247 likes

Total Posts

970 posts

Correct Reply

221 solutions
Top badges earned
Give Back 50
Give Back 5
Give Back 3
Give Back 25
Give Back 10
View profile
Feike_Visser1
Employee

15-10-2015

Can you try this?

${pageProperties['cq:lastModified'].toString}

Avatar

Avatar
Level 1
DimitrisZer
Level 1

Likes

0 likes

Total Posts

1 post

Correct Reply

0 solutions
View profile

Avatar
Level 1
DimitrisZer
Level 1

Likes

0 likes

Total Posts

1 post

Correct Reply

0 solutions
View profile
DimitrisZer
Level 1

02-04-2020

A little late response, but since I stumbled upon the same problem and came across this post, I am leaving this reply


You have to format it, ie. like so: 

${'yyyy-MM-dd' @ format=myDate}

Check this for more info:
https://github.com/adobe/htl-spec/blob/1.3/SPECIFICATION.md#1222-dates

Avatar

Avatar
Give Back 50
Employee
Feike_Visser1
Employee

Likes

247 likes

Total Posts

970 posts

Correct Reply

221 solutions
Top badges earned
Give Back 50
Give Back 5
Give Back 3
Give Back 25
Give Back 10
View profile

Avatar
Give Back 50
Employee
Feike_Visser1
Employee

Likes

247 likes

Total Posts

970 posts

Correct Reply

221 solutions
Top badges earned
Give Back 50
Give Back 5
Give Back 3
Give Back 25
Give Back 10
View profile
Feike_Visser1
Employee

15-10-2015

Sightly tries to call methods that are available on the object you supplied, just basic java reflection I would say.

Avatar

Avatar
Validate 1
MVP
Runal_Trivedi
MVP

Likes

45 likes

Total Posts

153 posts

Correct Reply

68 solutions
Top badges earned
Validate 1
Ignite 1
Give Back 5
Give Back 3
Give Back 10
View profile

Avatar
Validate 1
MVP
Runal_Trivedi
MVP

Likes

45 likes

Total Posts

153 posts

Correct Reply

68 solutions
Top badges earned
Validate 1
Ignite 1
Give Back 5
Give Back 3
Give Back 10
View profile
Runal_Trivedi
MVP

15-10-2015

Hi Fieke,

Thanks it certainly helped. But more interestingly it allowed me to call Date Modified - ${dateobj.getTime.toString}.

My doubt here is, how does sightly allow to call DATE, DATETIME API methods directly i.e dateobj.getTime, dateobj.getTime.getTime, dateobj.getWeekYear etc..

- Runal

Avatar

Avatar
Validate 1
MVP
Runal_Trivedi
MVP

Likes

45 likes

Total Posts

153 posts

Correct Reply

68 solutions
Top badges earned
Validate 1
Ignite 1
Give Back 5
Give Back 3
Give Back 10
View profile

Avatar
Validate 1
MVP
Runal_Trivedi
MVP

Likes

45 likes

Total Posts

153 posts

Correct Reply

68 solutions
Top badges earned
Validate 1
Ignite 1
Give Back 5
Give Back 3
Give Back 10
View profile
Runal_Trivedi
MVP

15-10-2015

Hi,

Thanks for the response but the snippet that I pasted in my query is sightly snippet only and it doesnt return anything.

I have gone through the tutorials but none mention how can a date property be accessed from sightly snippet.

- Runal

Avatar

Avatar
Validate 25
Level 10
smacdonald2008
Level 10

Likes

1,406 likes

Total Posts

12,671 posts

Correct Reply

2,278 solutions
Top badges earned
Validate 25
Validate 10
Validate 1
Give back 900
Give back 600
View profile

Avatar
Validate 25
Level 10
smacdonald2008
Level 10

Likes

1,406 likes

Total Posts

12,671 posts

Correct Reply

2,278 solutions
Top badges earned
Validate 25
Validate 10
Validate 1
Give back 900
Give back 600
View profile
smacdonald2008
Level 10

15-10-2015

This is all explained in this AEM doc topic:

http://docs.adobe.com/docs/en/aem/6-0/develop/sightly.html

More Sighty examples here:

http://experiencedelivers.adobe.com/cemblog/en/experiencedelivers/2014/01/sightly-preview-part1.html

<ul data-sly-list.child="${currentPage.listChildren}">
    <li>${child.title}</li>
</ul>