<p>I'm a total novice with Craft/Twig and I was hoping for some sort of simple and neat <code>append</code> function in Twig!</p>

<p>However, I've got close to a working solution using CSS, by overriding the Extract's <code>&lt;p&gt;</code> tags' usual behavior with <code>display: inline</code>, and enclosing the 'Continue reading…' in a <code>&lt;span&gt;</code> tag.</p>

<p><strong>Edit:</strong><br>
The following (including some additional logic for a 'Summary' field) seems to work well…</p>

<pre><code>&lt;div class="excerpts"&gt;

    {% if entry.summary %}
        {{ entry.summary }}
    {% else %}
        {{ entry.body.page(1) }}
    {% endif %}

    {% if entry.body.getTotalPages() &gt; 1 or entry.summary %}
        &lt;span&gt;&lt;a href="{{ entry.url }}" rel="nofollow"&gt;Continue reading…&lt;/a&gt;&lt;/span&gt;         
    {% endif %}

&lt;/div&gt;
</code></pre>

<p>…and…</p>

<pre class="lang-css prettyprint-override"><code>.excerpts p:last-of-type { display: inline; }
</code></pre>

CC BY-SA 3.0
2014-07-29T15:41:15.920Z
THIS is the way to go, Brian! I was so much in my Craft thinking that I didn't understand the problem as a whole. All you actually want to do is to STYLE the "continue reading..." link. And as we all know, styling should be done using css, semantically the link belongs outside of your paragraphs. Additionally I'd add `rel="nofollow"` to the link, as you don't want to rank for "Continue reading" at search engines.
carlcs
CC BY-SA 3.0
2014-07-29T16:03:20.280Z
Oh, and it's `p:last-of-type { display: inline; }`...
carlcs
CC BY-SA 3.0
2014-07-29T16:29:08.597Z
Now you only have to wait 2 days before you can accept your answer :D In the meantime, you could edit it to make it even more useful for future readers (add a complete css code snippet etc.).
carlcs
CC BY-SA 3.0
2014-07-29T15:05:11.407Z
2014-07-29T18:12:02.103Z
2014-07-29T18:12:02.103Z
Brian L
<p>I would write a Craft plugin with a twig extension.</p>

<pre><code>{% if entry.richTextFieldHandle.getTotalPages() &gt; 1 %}
  {{ entry.richTextFieldHandle.getPage(1)|continueReading('Continue reading…', entry.url)|raw }}
{% else %}
  {{ entry.richTextFieldHandle }}
{% endif %}
</code></pre>

<p><code>continueReading</code> plugin left as an exercise for the reader.</p>

CC BY-SA 3.0
2014-07-29T14:50:37.277Z
Marion, what about making `continueReading` an exercise for the answerer?
carlcs
CC BY-SA 3.0
2014-07-29T14:52:40.340Z
@ChristianSeelbach quite possible, but no promises.
Marion Newlevant
CC BY-SA 3.0
2014-07-29T15:00:33.123Z
YEY! Redactor is no easy to deal with. Still struggling on how to add [AND remove](https://github.com/aelvan/RedactorStyles-Craft#known-issues) inline tags with a custom button.
carlcs
CC BY-SA 3.0
2014-07-29T14:48:02.960Z
2014-07-29T14:48:02.960Z
Marion Newlevant
<p>To solve this properly you'd need to write a Craft plugin which also holds some sort of Redactor plugin.</p>

<p>But as a quick solution, how about using the <a href="http://twig.sensiolabs.org/doc/filters/striptags.html" rel="nofollow">striptags</a> filter? It'll remove <em>all</em> your tags though, meaning that you will also loose all other paragraph and styling tags.</p>



<pre class="lang-twig prettyprint-override"><code>{#
 # This comment is only necessary because of this bug:
 # http://meta.craftcms.stackexchange.com/questions/72/temporary-removal-of-twig-syntax-highlighting
 #}

&lt;p&gt;
    {{ entry.richTextFieldHandle.getPage(1)|striptags }}

    {% if entry.richTextFieldHandle.getTotalPages() &gt; 1 %}
        &lt;a href="{{ entry.url }}"&gt;Continue reading…&lt;/a&gt;
    {% endif %}
&lt;/p&gt;
</code></pre>

<p>You could also try to apply <a href="http://twig.sensiolabs.org/doc/filters/slice.html" rel="nofollow"><code>slice</code></a> filters. I'm not sure, but maybe this automatically leads to a <a href="http://twig.sensiolabs.org/doc/filters/raw.html" rel="nofollow">raw output</a> of your rich text, making all other tags not working as well.</p>

<pre class="lang-twig prettyprint-override"><code>{#
 # This comment is only necessary because of this bug:
 # http://meta.craftcms.stackexchange.com/questions/72/temporary-removal-of-twig-syntax-highlighting
 #}

&lt;p&gt;
    {{ entry.richTextFieldHandle.getPage(1)|slice(4)|slice(0, -4) }}

    {% if entry.richTextFieldHandle.getTotalPages() &gt; 1 %}
        &lt;a href="{{ entry.url }}"&gt;Continue reading…&lt;/a&gt;
    {% endif %}
&lt;/p&gt;
</code></pre>

CC BY-SA 3.0
2014-07-29T14:35:47.463Z
2014-07-30T06:06:47.263Z
2014-07-30T06:06:47.263Z
carlcs
<p>The code from the <a href="http://buildwithcraft.com/docs/rich-text-fields#templatin" rel="noreferrer">RichText documentation</a> appends the 'Continue reading…' link in a new block and on a new line:</p>

<pre class="lang-twig prettyprint-override"><code>{% for entry in craft.entries.section('blog') %}
        &lt;a href="{{ entry.url }}"&gt;{{ entry.title }}&lt;/a&gt;
        {{ entry.richTextFieldHandle.getPage(1) }}
        {% if entry.richTextFieldHandle.getTotalPages() &gt; 1 %}
            &lt;a href="{{ entry.url }}"&gt;Continue reading…&lt;/a&gt;
        {% endif %}
{% endfor %}
</code></pre>

<p>Any ideas how to append the 'Continue reading…' link inside the final <code>&lt;/p&gt;</code> tag generated by Redactor at the end of the final paragraph, i.e. as a continuation of the Excerpt text, and on the same line?</p>

<templating><richtext><redactor>
How to append 'Continue reading…' link within the last paragraph of the Excerpt
# How to append 'Continue reading…' link within the last paragraph of the Excerpt

(Asked by: username_0 on 2014-07-29)

The code from the RichText documentation appends the 'Continue reading…' link in a new block and on a new line:
{% for entry in craft.entries.section('blog') %}
        {{ entry.title }}
        {{ entry.richTextFieldHandle.getPage(1) }}
        {% if entry.richTextFieldHandle.getTotalPages() > 1 %}
            Continue reading…
        {% endif %}
{% endfor %}

Any ideas how to append the 'Continue reading…' link inside the final  tag generated by Redactor at the end of the final paragraph, i.e. as a continuation of the Excerpt text, and on the same line?

**Tags:** templating, richtext, redactor


---

## 3 answers

### Answer by username_0 on 2014-07-29. Score: 5 | Accepted answer

I'm a total novice with Craft/Twig and I was hoping for some sort of simple and neat append function in Twig!
However, I've got close to a working solution using CSS, by overriding the Extract's  tags' usual behavior with display: inline, and enclosing the 'Continue reading…' in a  tag.
Edit:
The following (including some additional logic for a 'Summary' field) seems to work well…


    {% if entry.summary %}
        {{ entry.summary }}
    {% else %}
        {{ entry.body.page(1) }}
    {% endif %}

    {% if entry.body.getTotalPages() > 1 or entry.summary %}
        Continue reading…         
    {% endif %}



…and…
.excerpts p:last-of-type { display: inline; }

> **Comments:**
> **username_1**: THIS is the way to go, Brian! I was so much in my Craft thinking that I didn't understand the problem as a whole. All you actually want to do is to STYLE the "continue reading..." link. And as we all know, styling should be done using css, semantically the link belongs outside of your paragraphs. Additionally I'd add `rel="nofollow"` to the link, as you don't want to rank for "Continue reading" at search engines.  
> **username_1**: Oh, and it's `p:last-of-type { display: inline; }`...  
> **username_1**: Now you only have to wait 2 days before you can accept your answer :D In the meantime, you could edit it to make it even more useful for future readers (add a complete css code snippet etc.).  

---

### Answer by username_2 on 2014-07-29. Score: 1

I would write a Craft plugin with a twig extension.
{% if entry.richTextFieldHandle.getTotalPages() > 1 %}
  {{ entry.richTextFieldHandle.getPage(1)|continueReading('Continue reading…', entry.url)|raw }}
{% else %}
  {{ entry.richTextFieldHandle }}
{% endif %}

continueReading plugin left as an exercise for the reader.

> **Comments:**
> **username_1**: Marion, what about making `continueReading` an exercise for the answerer?  
> **username_2**: @ChristianSeelbach quite possible, but no promises.  
> **username_1**: YEY! Redactor is no easy to deal with. Still struggling on how to add [AND remove](https://github.com/aelvan/RedactorStyles-Craft#known-issues) inline tags with a custom button.  

---

### Answer by username_1 on 2014-07-29. Score: 1

To solve this properly you'd need to write a Craft plugin which also holds some sort of Redactor plugin.
But as a quick solution, how about using the striptags filter? It'll remove all your tags though, meaning that you will also loose all other paragraph and styling tags.
{#
 # This comment is only necessary because of this bug:
 # http://meta.craftcms.stackexchange.com/questions/72/temporary-removal-of-twig-syntax-highlighting
 #}


    {{ entry.richTextFieldHandle.getPage(1)|striptags }}

    {% if entry.richTextFieldHandle.getTotalPages() > 1 %}
        Continue reading…
    {% endif %}


You could also try to apply slice filters. I'm not sure, but maybe this automatically leads to a raw output of your rich text, making all other tags not working as well.
{#
 # This comment is only necessary because of this bug:
 # http://meta.craftcms.stackexchange.com/questions/72/temporary-removal-of-twig-syntax-highlighting
 #}


    {{ entry.richTextFieldHandle.getPage(1)|slice(4)|slice(0, -4) }}

    {% if entry.richTextFieldHandle.getTotalPages() > 1 %}
        Continue reading…
    {% endif %}


---

