I want to compare a node's creation date and modified date in Twig, and it drives me bonkers. I've looked at various examples and snippets as part of this, this, this or this external source.
Using Drupal 8, Bootstrap 3, Bootstrap Layouts, Display Suite, and a custom sub-theme, I have a twig template customising what is going to be displayed and how. This custom template is a copy of the default bootstrap layouts 1 column template.
Within the template, I can access and print the dates using this:
{{ main.content.node_changed_date }}
{{ main.content.node_post_date }}
and all is well.
However, I want to compare the dates in my template like so:
{% if main.content.node_post_date|date('Y-m-d') > main.content.node_changed_date|date('Y-m-d') %}
{{ main.content.node_post_date }}
{% endif %}
But this barks at me with the following error:
The website encountered an unexpected error. Please try again later.
TypeError: DateTime::__construct() expects parameter 1 to be string, array given in DateTime->__construct() (line 455 of /home/michel/devel/vendor/twig/twig/lib/Twig/Extension/Core.php).
DateTime->__construct(Array, Object) (Line: 455)
twig_date_converter(Object, Array, Object) (Line: 380)
twig_date_format_filter(Object, Array, 'Y-m-d') (Line: 77)
Yes, I use Composer to manage my installation.
What am I doing wrong?
Pulling my hairs
Michel