I have a rich text field, e.g. for defining an image caption. Now in my template I would like to prepend some text to the content of the rich text field, e.g. Figure 1: [rich text]. Is this possible? The content of the paragraph-tag of the rich text field should include the prepended text.
If you want to prepend another paragraph you could to this:
{% set paragraphs = entry.body|split('</p>') %}
{% for paragraph in paragraphs %}
{% if loop.index == 1%}
<p>Prepended Custom Text</p>
{% endif %}
{{paragraph|raw}}
{% endfor %}
If you want to display a custom string in the first paragraph itself you could do this:
{% set paragraphs = entry.body|split('</p>') %}
{% for paragraph in paragraphs %}
{% if loop.index == 1%}
{% set paragraph = paragraph|replace({'<p>': '<p>My custom prepended Text '}) %}
{% endif %}
{{paragraph|raw}}
{% endfor %}
This looks a little bit hacky tough there are probably prettier ways to do so.