New answers tagged

0 votes
Accepted

Get array of titles instead of whole collection of entries' attributes

Ended up using GraphQL Let's say we have an entry, and from that entry we need to retrieve the "title", and the custom field "relatedProducts", which is an entry type field, and ...
3 votes
Accepted

How to reuse "functional code" in multiple twig files

As Steve mentioned, there are a few different approaches, but for me I'd reach for embed in this situation. https://twig.symfony.com/doc/3.x/tags/embed.html By combining with the parent() function, ...
  • 4,084
2 votes

How to reuse "functional code" in multiple twig files

You can't pass a variable from an included template back to the template that called it. But you still have at least three options (that I can think of) to achieve the kind of reusability that you're ...
2 votes

Loop last error getting entries

Updated answer: make sure your for loop is calling .all() and {{loop.last}} should work. You'll need to use {% if loop|last %}. This has changed in Twig 3 (which i guess Craft 4 is now using). See: ...
  • 508
1 vote

How to trim each string in an array?

The other way is you can use array map for this. {% set array_checked_values = submission|split(',')|map(c => c|trim) %}
  • 507
0 votes

How to trim each string in an array?

I have resolved it by myself. Although it will be an roundabout way, create another array. When each of the values is migrated, the string can be trimmed. {% set array_checked_values = submission[...
  • 401
0 votes
Accepted

Accessing eager loaded Collections data

The reason that you get that error is probably you have some of serie that doens't has client, so during the loop you need to check whether the serie has client or not, kind of like this: {% if serie....
  • 507

Top 50 recent answers are included