Last active
September 9, 2019 05:55
-
-
Save piotrpog/d106c79323ab6c4d6131a1dc752ec0d6 to your computer and use it in GitHub Desktop.
Macro for setting default date format. More info: http://craftsnippets.com/articles/working-with-dates-in-craft-cms-templates
This file contains hidden or 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