0

I created a paragraph (machine name date) with 2 fields (date_1 and date_2). When adding this paragraph (Entity Reference field_date) to my content type Agenda I choose the 'Allowed number of values: unlimited' option.

I create a node for content type Agenda with multiple fields of the field_date field.

Now I'm changing the output of the fields of the paragraphs in a paragraph--date.html.twig template. But I want to know/track in this template if there is a multiple field and for example if it is the first or the last value.

How is this possible?

  • When you want to keep track of multiple value fields, for example add classes to the first and last value, then use a field template like field--node--field-date--agenda.html.twig – 4k4 Jan 15 '18 at 12:16
  • Thanks, but I need to have this info in the paragraph template mentioned, not in the field template. Any suggestions for that? – Joost Jan 15 '18 at 15:34
  • There is no straightforward way, because entities in an entity reference field are unaware of where they are rendered and this can change without that the rendered entity is invalidated. – 4k4 Jan 15 '18 at 16:01
  • Ah to bad. Since there is no neat way to fix this I solved it by creating two extra hidden fields to the paragraph one for the current position and one of the total number of fields. With a little jQuery it's easy to fill these out so I can read this information in my paragraph template. – Joost Jan 16 '18 at 7:49
  • jQuery is a good hint, although most times CSS with multiple selectors should do it. – 4k4 Jan 16 '18 at 8:05

Your Answer

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

Browse other questions tagged or ask your own question.