[英]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.