1

How to show few lines of a large paragraph in a table. The following code shows all of the lines and they can't place in table correctly.

index.html.twig

    {% for new in news %}
    <tr>
        <th scope="row">{{ new.id }}</th>
        <td>{{ new.topic }}</td>
        <td>{{ new.article }}</td>
    </tr>
    {% endfor %}
edbighead
  • 5,607
  • 5
  • 29
  • 35
  • Possible duplicate of https://stackoverflow.com/questions/13143001/symfony-2-twig-limit-the-length-of-the-text-and-put-three-dots ? – Manzolo Aug 28 '19 at 07:23

1 Answers1

0

First of all, mention a class name for your td tag,
for example

<td class="article"></td>

In which you are limiting number of characters to show.

and put this script in your file and your code will look something like this
For limiting article section ->

{% for new in news %}
    <tr>
        <th scope="row">{{ new.id }}</th>
        <td>{{ new.topic }}</td>
        <td class="article">{{ new.article }}</td>
    </tr>
{% endfor %}

Now include this script in your file

<script>
    $(".article").text(function(index, currentText) {
        return currentText.substr(0, 50); // You can change 50 to as many characters, you want to display
    });
</script>

I am assuming that you are using jquery library,
Hope It helps...

Riosant
  • 344
  • 3
  • 15