到目前为止,我可以按照以下步骤进行操作:
{% for post in collections.posts %}
<div class="post" style="{% if loop.index > 1 %} display: none;{% endif %}">
<a href="{{ post.url }}">{{ post.data.title }}</a>
<p class="text-sm text-gray-600">
{{ post.date | humanDate }}.
</p>
{{ post.templateContent | safe }}
</div>
{% endfor %}
问题是网站仍然会加载其余帖子,只是它们被隐藏了。如何停止其余帖子的加载?
如果需要显示的唯一元素,则只能选择列表的最后一个元素:
<div class="post">
{{ posts[-1].templateContent | safe }}
</div>