I'm trying to use Liquid to include the current year in my site footer. According to the official documentation, this should do the trick:
{{ 'now' | date: '%Y' }}
However, this just outputs the word 'now'.
Does anyone know how to get the current year using Liquid?
Hey Jerad,
I think you're referring to documentation from Shopify. For NationBuilder, our date and time availabilities can be found here.
Currently, date and time are variables associated with events. They would look like this:
{{ event.event.local_start_at | date: '%A, %B %d, %Y at %I:%M %p' }}
Another interesting variable is the one that can display when the last time the site stats where updated:
{{ settings.stats_updated_at }}
It is easy to add in a time and date js code though to do the same thing. You can find many examples on the net that do this. Here is one example that you could modify for your purposes that outputs the date in the format Tuesday, July 16, 2013:
<script language="JavaScript">
var now = new Date();
var days = new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
var months = new Array('January','February','March','April','May','June','July','August','September','October','November','December');
var date = ((now.getDate()<10) ? "0" : "")+ now.getDate();
function fourdigits(number) {
return (number < 1000) ? number + 1900 : number;
}
today = days[now.getDay()] + ", " +
months[now.getMonth()] + " " +
date + ", " +
(fourdigits(now.getYear())) ;
document.write(today);
</script>
Showing 8 reactions
Sign in with
You can totally place the current date using a div or a span. Instead of dropping the script into the html panel for the content of your page, you’ll want to put it at the bottom of the page template like this:
<script>
$(document).ready(function() {
$(“.now”).html($.datepicker.formatDate(‘dd M yy’, new Date()));
});
</script>
And then in your content, find where you’d like to put your date, and insert a div or span with class=“now” inline with your text(span will usually work better for this). The html editor is slightly wonky and will delete a div or span that doesn’t have any content in it, so I would insert a “.” or some other character so that the element is actually inserted into your content.
For example, the code in my html content editor looks like this:
<p>This is today’s date:<span class=“now”>.</span></p>
And is displayed on my site like this:
This is today’s date:13 Oct 2015
Hope this helps! Let me know if you have any trouble getting this working.
Would place “13 Apr 2014” inside the span element. The datepicker widget also has the ability to display in different languages using $.datepicker.regional[ “fr” ]
{% assign current_year = settings.stats_updated_at | date: ‘%Y’ %}
<p class=“copyright”>© Copyright 2012-{{current_year}}. All rights reserved. {{site.long_name}}. <a href=“#”>Privacy Policy</a></p>
See any problem with this? It appears to work and I assume the stats are updated at least daily?