[英]How to show few lines of o large paragraph with symfony3.4 from mysql database
如何在表格中顯示大段落的幾行。 以下代碼顯示了所有行,它們無法正確放置在表中。
index.html.twig
{% for new in news %}
<tr>
<th scope="row">{{ new.id }}</th>
<td>{{ new.topic }}</td>
<td>{{ new.article }}</td>
</tr>
{% endfor %}
首先,為您的td標簽提及一個類名,
例如
<td class="article"></td>
您要限制顯示的字符數。
並將此腳本放入文件中,您的代碼將如下所示
對於限制文章部分->
{% for new in news %}
<tr>
<th scope="row">{{ new.id }}</th>
<td>{{ new.topic }}</td>
<td class="article">{{ new.article }}</td>
</tr>
{% endfor %}
現在將此腳本包含在文件中
<script>
$(".article").text(function(index, currentText) {
return currentText.substr(0, 50); // You can change 50 to as many characters, you want to display
});
</script>
我假設您正在使用jquery庫,
希望能幫助到你...
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.