I'm new to aem. I'm trying to implement the following example in aem by using sightly. currently im working on aem 6.1.
can you please guide me how can i access current time in sightly. I'm using dialog boxes to show greeting messages according to current time.
<div data-sly-use.clientlibInclude="${'/libs/granite/sightly/templates/clientlib.html'}"></div>
<output data-sly-call="${clientlibInclude.css @ categories='angular-global-category'}" data-sly-unwrap />
<html> `enter code here`
<head>
<title>Greeting Message using JavaScript</title>
</head>
<body>
<section class="intro">
<h1> <label id="lblGreetings"></label></h1></section>
</body>
<script>
var myDate = new Date();
var hrs = myDate.getHours();
var greet;
if (hrs < 12)
greet = 'Good Morning';
else if (hrs >= 12 && hrs <= 17)
greet = 'Good Afternoon';
else if (hrs >= 17 && hrs <= 24)
greet = 'Good Evening';
document.getElementById('lblGreetings').innerHTML =
'' + greet + ' Julio';
</script>
</html>
There's no native objects that contain server date information in sightly. To print a date with sightly you need to have a Model related to it and use it within sightly. You can have a javascript model or a java one. quick js guide found on the net: http://blogs.adobe.com/experiencedelivers/experience-management/htl-javascript-use-api/
If you'd want to go with Java I'd advise using SlingModels or Slice for modelling.
Seems to me you didn't do much reading on sighlty. Please read the docs first.