1

I'm trying to render both start and end date on a node template in Drupal 8 from the Date range field from the content type. I've tried multiple ways to no avail.

-- Only shows start date --

{{ kint(node.field_date_range.value ) }} 

{% if node.field_date_range %}
{{ node.field_date_range.value|date(format='l M j') }}
{% endif %}

  • This works: {{ node.field_date_range.value|date(format='l M j') ~ ' thru ' ~ node.field_date_range.end_value|date(format='l M j') }} – Brad Dec 30 '17 at 15:58
  • 1
    Why do you need to render the field directly instead of using the formatters? – mpdonadio Dec 30 '17 at 16:52
  • Your first comment claims you have found a solution: you should post it as an update in the original question, so people will able to use it. – ssibal Jan 3 '18 at 13:05
1

Here is the full solution that allowed me to separate the content into a traditional calendar mock-up on a node--events--html.twig:

<div class="cal-wrapper">

{% if node.field_date_range.value %}
  <div class="cal-day">
  {{ node.field_date_range.value|date(format='l')  ~ ' thru ' ~ node.field_date_end_range_value|date(format='l') }}
{% else %}
  {{ node.field_date.value|date(format='l') }}
  </div>
{% endif %}

{% if node.field_date_range.value %}
  <div class="cal-month">
  {{ node.field_date_range.value|date(format='M')  ~ ' thru ' ~ node.field_date_end_range_value|date(format='M') }}
 {% else %}
  {{ node.field_date.value|date(format='M') }}
 </div>
 {% endif %}

 {% if node.field_date_range.value %}
   <div class="cal-main-date">
   {{ node.field_date_range.value|date(format='j')  ~ ' thru ' ~ node.field_date_end_range_value|date(format='j') }}
 {% else %}
   {{ node.field_date.value|date(format='j') }}
   </div>
 {% endif %}

 </div>
| improve this answer | |
0

For the end value of a 'data_range' field you can use: '.end_value', instead of '.value', example:

{% if node.field_date_range %}
  {{ node.field_date_range.end_value|date(format='l M j') }}
{% endif %} 

Sorry my bad english.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.