You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Sep 25, 2021. It is now read-only.
In my template I'd like to format my dates and have them update periodically.
I saw the following in the documentation:
<span>Year: {% var d=new Date(); print(d.getFullYear()); %}</span>
my question is how to use my own custom function, nicetime(), in my template instead of getFullYear().
here's what i'd like to work, but doesn't:
<span>Year: {% var d=nicetime(); print(d); %}</span>
here's what nicetime() looks like:
function nicetime(){ var time = new Date(), comment_date = setInterval(function() { var time2 = time_since(time.getTime()/1000); return time2; // 1 second ago, then 2 seconds ago, and so on... }, 1000); }
time_since() formats the code in Facebook-style: "2 seconds ago...".
any thoughts would be greatly appreciated?
The text was updated successfully, but these errors were encountered:
The JavaScript Templates generate a string, not a DOM collection, so you can't use setInterval in the way you intended.
I would advise you to make use of a span element with a specific ID that can be updated periodically by updating the DOM element with the specified ID.
That ID could be generated by a custom helper function.
hi Sebastian, thanks for the reply. Sorry to have bothered you again on this. It took me a long time, but I actually just arrived at exactly the solution you just said, try this jsfiddle: http://jsfiddle.net/SpYXM/89/. It works!
Again, thanks for your help. I'm using your Multi-upload plugin too (like the rest of the world). You do really great stuff. Thanks for taking the time for us little people.
In my template I'd like to format my dates and have them update periodically.
I saw the following in the documentation:
<span>Year: {% var d=new Date(); print(d.getFullYear()); %}</span>
my question is how to use my own custom function,
nicetime()
, in my template instead ofgetFullYear()
.here's what i'd like to work, but doesn't:
<span>Year: {% var d=nicetime(); print(d); %}</span>
here's what
nicetime()
looks like:function nicetime(){ var time = new Date(), comment_date = setInterval(function() { var time2 = time_since(time.getTime()/1000); return time2; // 1 second ago, then 2 seconds ago, and so on... }, 1000); }
time_since()
formats the code in Facebook-style: "2 seconds ago...".any thoughts would be greatly appreciated?
The text was updated successfully, but these errors were encountered: