I havea piece ofjscodethat Iwantto workin Umbraco. I'm makingopening hourson a website. Iwould liketo be able toseethe opening hours ofalldays,butthe weekdayfortodayhas to behighlighted. Somethinglike this:
There should not be any need for having inline JavaScript above.
I believe you should be able to use the built in Umbraco XSLT extension called umbraco.library:CurrentDate() to compare with the chosen dates and then hightlight the date that matches the current one.
If you just need to highlight the weekday you can format the date returned by CurrentDate() using the umbraco.library:FormatDateTime() extension.
Hope the above pointers make sense - let me know if you need further explanation.
It should be fairly easy to set this up in a macro using Razor. You can retrieve the day from the server time using this:
@DateTime.Now.DayOfWeek
You should then be able to loop through your opening hours and construct your markup, comparing each day with the the one set on server and adding your class when it matches.
How to set a date?
Hi
I have a piece of js code that I want to work in Umbraco.
I'm making opening hours on a website.
I would like to be able to see the opening hours of all days, but the weekday for today has to be highlighted.
Something like this:
Mon 9-15
Tues 9-16
<b> Wed 8-16 </ b>
Thurs 9-16
Fri 9-12
Mon, Tues, Thurs and Friday is faded out and Wednesday are in bold.
I shall then have it to automatically switch :-)
The code I have for this is:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style type="text/css">
.bold{
font-family:arial, helvetica; font-size:12px; font-weight:bold;
}
.gray{
color:gray;
}
</style>
<script type="text/javascript">
function marker(){
var weekday=Array("søn","man","tir","ons","tor","fre","lør");
var d = new Date();
var n = d.getDay();
if(n==0 || n==5 || n==6);
else document.getElementById(weekday[n]).className="bold";
}
</script>
</head>
<body>
<div class ="gray" id="man">man 9-15</div>
<div class ="gray" id="tir">tir 9-16</div>
<div class ="gray" id="ons">ons 8-16</div>
<div class ="gray" id="tor">tor 9-16</div>
<div class ="gray" id="fre">fre 9-12</div>
<script type="text/javascript">
marker();
</script>
</body>
</html>
My problem is that I would like it to work serverside, instead of relying on the time set on the users computer.
Can anybody help me. :-)
I have no ide if I should write this in a macro or somewere else.
Hi Kate
There should not be any need for having inline JavaScript above.
I believe you should be able to use the built in Umbraco XSLT extension called umbraco.library:CurrentDate() to compare with the chosen dates and then hightlight the date that matches the current one.
If you just need to highlight the weekday you can format the date returned by CurrentDate() using the umbraco.library:FormatDateTime() extension.
Hope the above pointers make sense - let me know if you need further explanation.
/Jan
It should be fairly easy to set this up in a macro using Razor. You can retrieve the day from the server time using this:
You should then be able to loop through your opening hours and construct your markup, comparing each day with the the one set on server and adding your class when it matches.
Hi
Im trying to use Razor, but I have never tried that before. Im getting an arror when i try making an if()
This is what I have done so fare ;-)
What im I doing wrong?
Hi Jan
I have also tried your exampel and it looks like it works. Now I would like to get a weekly number out and not the word "Monday".
Monday = 1
Tuesday = 2
...
next monday = 1 (again)
Then I can use it in an <xsl:choose>
This is what I got so fare:
It works now :-)
I used: <xsl:variable name="today" select="Exslt.ExsltDatesAndTimes:dayinweek()"/>
Hi Jan and SC web Team
Thanks for pointing me in the right direction.
I made it work i xslt but I have not figured it out in Razor yet ;-)
Here is what I ended up with
Thanks again :-)
is working on a reply...