<p>If you want to prepend another paragraph you could to this:</p>

<pre><code>{% set paragraphs = entry.body|split('&lt;/p&gt;') %}
{% for paragraph in paragraphs %}
  {% if loop.index == 1%}
    &lt;p&gt;Prepended Custom Text&lt;/p&gt;
  {% endif %}
    {{paragraph|raw}}
{% endfor %}
</code></pre>

<p>If you want to display a custom string in the first paragraph itself you could do this:</p>

<pre><code>{% set paragraphs = entry.body|split('&lt;/p&gt;') %}
{% for paragraph in paragraphs %}
  {% if loop.index == 1%}
    {% set paragraph = paragraph|replace({'&lt;p&gt;': '&lt;p&gt;My custom prepended Text '}) %}
  {% endif %}
    {{paragraph|raw}}
{% endfor %}
</code></pre>

<p>This looks a little bit hacky tough there are probably prettier ways to do so.</p>

CC BY-SA 3.0
2016-04-08T09:52:27.220Z
2016-04-08T09:52:27.220Z
Marco Schuler
<p>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. <em>Figure 1:</em> [rich text]. Is this possible? The content of the paragraph-tag of the rich text field should include the prepended text.</p>

<templating><richtext>
How to append / prepend into a rich text field
# How to append / prepend into a rich text field

(Asked by: username_0 on 2016-04-08)

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.

**Tags:** templating, richtext

---

## 1 answers

### Answer by username_1 on 2016-04-08. Score: 3 | Accepted answer

If you want to prepend another paragraph you could to this:
{% set paragraphs = entry.body|split('') %}
{% for paragraph in paragraphs %}
  {% if loop.index == 1%}
    Prepended Custom Text
  {% 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('') %}
{% for paragraph in paragraphs %}
  {% if loop.index == 1%}
    {% set paragraph = paragraph|replace({'': 'My custom prepended Text '}) %}
  {% endif %}
    {{paragraph|raw}}
{% endfor %}

This looks a little bit hacky tough there are probably prettier ways to do so.


---

