M
M
microfrog2022-04-04 20:56:46
Drupal
microfrog, 2022-04-04 20:56:46

How to display the names of a material with a specific type and the associated subtype name?

Hi All!

Drupal 8.

Neither Drupal, nor Twig, nor PHP's object model is strong. :(

There are materials with the machine name direction. There are materials with the machine name direction_part associated with the direction.

The structure is approximately the following: Physics
-
Quantum
- Classical
- Relativistic
Chemistry
- Organic
- Inorganic
Biology
- Plants
- Animals

view

This doesn't work.

{% for item in direction %}
    {{ item.title }}
       {% for subitem in item.direction_part %}
            {{ subitem.title }}
       {% endfor %}
    {% endfor %}


Help!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
antiden, 2022-04-05
@donda

{% set posts = node.direction %}
{% for item in posts %}
    {% set title = item.title.value %}
    {% set parts = item.direction_part %}
    {{ title }}
    {% for subitem in parts %}
        {% set subtitle = subitem.entity.title.value %}
        {{ subtitle }}
    {% endfor %}
{% endfor %}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question