Drupal Answers Asked on December 17, 2021
I have a node which shows content from the body field. I want to add a another paragraph or a block between between the first and the second paragraph, after the first </p>
and before the second <p>
tag.
But in my template to output the body there’s only {{ content.body }}
.
Drupal 7 had something like block in block. How can I do the same in Drupal 8?
I resolved my issue, using solution below
{% set Paragraphs = node.body.value|split('</p>') %}
{% set paragraphHalf = (Paragraphs|length / 2)|round %}
{% if paragraphHalf %}
{% for paragraph in Paragraphs %}
{% if paragraphHalf == 1 or loop.index % paragraphHalf == 1 -%}
{% endif %}
{{ paragraph|raw }}
{% if loop.last or loop.index % paragraphHalf == 0 -%}
{{ insert item }}
{% endif %}
{% endfor %}
{% endif %}
Answered by pr1859 on December 17, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP