0

Drupal 8.x

I have 2 quick questions. I have the following node template node--briefing--teaser.html.twig

<div>
  <span>{{ date }}</span>
  <span>{{ label }}</span>
  <a href="{{ content.links.uri }}"></a>
</div>

Now the questions are:

  • How can I format the date to the following d/m/Y
  • How can I get the URI of the read more field (links)

With a normal link field you can simply do content.my_link.0['#url'] to get this but that doesn't seem to be the case with the node links field.

Thanks in advance!

6
  • @Hudri I already tried those answers and none of them gave any output. I guess the Links field is formatted differently ? Sep 20, 2019 at 9:09
  • Sorry, I misunderstood your question, I thought you meant a "real" URL field. I never use that weirdo pseudo "Links" field.
    – Hudri
    Sep 20, 2019 at 9:24
  • 1
    If it is of any help, you can get the URL to the node full view using {{ url }}, see api.drupal.org/api/drupal/…
    – Hudri
    Sep 20, 2019 at 9:27
  • Yeah I just had to use the URL attribute in twig to get what I want. Sep 20, 2019 at 9:27
  • 2
    Possible duplicate of How to get the valid URL of a Link field from within a Twig template?
    – user72672
    Sep 20, 2019 at 9:35

1 Answer 1

1

Answer for the date formating: {{ date.value|date('U')|format_date('custom', 'j/m/Y') }}

For the URI investigate the data structure with twig vardumper.

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.