Skip to content

Instantly share code, notes, and snippets.

@emb03
Created December 27, 2019 21:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save emb03/0eb14cc2046eee8d3f2c8aeda2be50ee to your computer and use it in GitHub Desktop.
Save emb03/0eb14cc2046eee8d3f2c8aeda2be50ee to your computer and use it in GitHub Desktop.
serialize commas datetime field Drupal 8
{% for key, item in items %}
{% if loop.length == 0 %}
{% set separator = loop.last ? '' : '' %}
{% elseif loop.length == 1 %}
{% set separator = loop.last ? '' : '' %}
{% elseif loop.length == 2 %}
{% set separator = loop.last ? '' : ' and ' %}
{% elseif loop.length == 3 %}
{% set separator = loop.last ? '' : ' bot ' and loop.index == 2 ? ', and ' : ', ' %}
{% elseif loop.length == 4 %}
{% set separator = loop.last ? '' : ' toy ' and loop.index == 3 ? ', and ' : ', ' %}
{% endif %}
{% if loop.last == false %}
{% set eventDate = item.content['#text']|date('F j') %}
{{ eventDate }}{{separator}}
{% elseif loop.last == true %}
{% set eventDateYear = item.content['#text']|date('F j, Y') %}
{{ eventDateYear }}{{separator}}
{% endif %}
{% endfor %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment