Macro for setting default date format. More info: http://craftsnippets.com/articles/working-with-dates-in-craft-cms-templates
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{%- macro defaultDateFormat(date, additionalAttributes) -%} | |
{# v1 #} | |
{% if date is defined %} | |
{# settings #} | |
{% set format = 'medium' %} | |
{# logic #} | |
{% set attributes = { | |
text: date|date(format), | |
datetime: date|date('yy-m-d') | |
} %} | |
{% if additionalAttributes is defined and additionalAttributes is not iterable %} | |
{% set attributes = attributes|merge({class: additionalAttributes}) %} | |
{% elseif additionalAttributes is iterable %} | |
{% set attributes = attributes|merge(additionalAttributes) %} | |
{% endif %} | |
{{tag('time',attributes)}} | |
{% endif %} | |
{%- endmacro -%} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment