How to remove duplicate values in this code, if they are in "{{ post.entity.name.value }}"?
{% block paragraph %}{% block content %}
{% for post in paragraph.field_post %}
{% if loop.last %}
{% set separator = '' %}
{% else %}
{% set separator = ',' %}
{% endif %}
{{ post.entity.name.value }}{{ separator }}
{% endfor %}
{% endblock %}{% endblock paragraph %}
I have a "Paragraph" type field. In the paragraph I have two fields: place of work (node reference) and position (taxonomy field).
Sometimes there is a need to display only the values of taxonomy fields on the site, and they can be repeated, because there may be several places of work. An employee can work in the same positions in several places. How do I remove duplicates in the paragraph display mode template?
As usual, I turned to ChatGPT, she gave me this solution
{% for post in paragraph.field_post %}{% set unique_names = post.entity.name.value|split(',')|batch(1)|map(item => item|unique)|join(',') %}{{ unique_names }}{% endfor %}
But there is a problem. The "unique" filter is not a standard filter in Twig. It can only be accessed by using third-party Twig extensions or Composer packages :(