Skip to main content

Improvements:

  1. if you strip tags you should |trim to get rid of whitespace
  2. trim on word boundary - see below slice() and split()
  3. Use ellipsis (…) rather than "..."
  4. |raw the output

{% set text = content.field_header_intro|render|striptags|trim %}

{{ (text|length > 200 ? text|slice(0, 201)|split(' ')|slice(0, -1)|join(' ') ~ '&hellip;' : text)|raw }}</code>

Improvements:

  1. if you strip tags you should |trim to get rid of whitespace
  2. trim on word boundary - see below slice() and split()
  3. Use ellipsis (&hellip;) rather than "..."
  4. |raw the output

{% set text = content.field_header_intro|render|striptags|trim %}

{{ (text|length > 200 ? text|slice(0, 201)|split(' ')|slice(0, -1)|join(' ') ~ '&hellip;' : text)|raw }}</code>

Improvements:

  1. if you strip tags you should |trim to get rid of whitespace
  2. trim on word boundary - see below slice() and split()
  3. Use ellipsis (&hellip;) rather than "..."
  4. |raw the output

{% set text = content.field_header_intro|render|striptags|trim %}

{{ (text|length > 200 ? text|slice(0, 201)|split(' ')|slice(0, -1)|join(' ') ~ '&hellip;' : text)|raw }}

Better formatting in my answer
Source Link
Duncanmoo
  • 3k
  • 1
  • 33
  • 54

Improvements:

  1. if you strip tags you should |trim to get rid of whitespace

    if you strip tags you should |trim to get rid of whitespace
  2. trim on word boundary

    trim on word boundary - see below slice() and split()
  3. Use ellipsis rather than ... (|raw the output)

    {% set text = content.field_header_intro|render|striptags|trim %}

    {{ (text|length > 200 ? text|slice(0, 201)|split(' ')|slice(0, -1)|join(' ') ~ '…' : text)|raw }}

    Use ellipsis (&hellip;) rather than "..."
  4. |raw the output

{% set text = content.field_header_intro|render|striptags|trim %}

{{ (text|length > 200 ? text|slice(0, 201)|split(' ')|slice(0, -1)|join(' ') ~ '&hellip;' : text)|raw }}</code>

Improvements:

  1. if you strip tags you should |trim to get rid of whitespace

  2. trim on word boundary

  3. Use ellipsis rather than ... (|raw the output)

    {% set text = content.field_header_intro|render|striptags|trim %}

    {{ (text|length > 200 ? text|slice(0, 201)|split(' ')|slice(0, -1)|join(' ') ~ '…' : text)|raw }}

Improvements:

  1. if you strip tags you should |trim to get rid of whitespace
  2. trim on word boundary - see below slice() and split()
  3. Use ellipsis (&hellip;) rather than "..."
  4. |raw the output

{% set text = content.field_header_intro|render|striptags|trim %}

{{ (text|length > 200 ? text|slice(0, 201)|split(' ')|slice(0, -1)|join(' ') ~ '&hellip;' : text)|raw }}</code>

Source Link
Duncanmoo
  • 3k
  • 1
  • 33
  • 54

Improvements:

  1. if you strip tags you should |trim to get rid of whitespace

  2. trim on word boundary

  3. Use ellipsis rather than ... (|raw the output)

    {% set text = content.field_header_intro|render|striptags|trim %}

    {{ (text|length > 200 ? text|slice(0, 201)|split(' ')|slice(0, -1)|join(' ') ~ '…' : text)|raw }}