Skip to content

fosterinteractive/drupal_twig_date_range

Repository files navigation

#twig_custom_date_range_filter#

Module adds a Custom Twig filter to show dates ranges as short as possible.

This module is not very flexible, so it is more a proof of concept.

##Example Output##

  • Same Month & Year = Aug 2-4, 2016
  • Same Year = Jul 31 - Aug 4, 2016
  • Different Years = Dec 31, 2016 - Jan 2, 2017
  • No "End" Date = Dec 31, 2016

Installation

  • Enable Module
  • Create 2 date fields on your node "start_date" and "end_date", 1 value only.
  • Update the node template
  • In Twig, use node.field_start_date.value (not content.field_start_date)
  • Pipe |date_range and use the node.field_start_end_date.value as the argument

Usage

<!-- node--type.html.twig -->

<h2 class="c-date">
  {{ node.field_start_date.value|date_range(node.field_end_date.value) }}
</h2>

Licenced under GPL 2

About

Custom Twig filter to show dates ranges as short as possible. Eg Aug 2-4 2016, Jul 31 - Aug 4, 2016

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages