文章

文章模板渲染文章页面,其中包含文章的全部内容,以及供客户选择的评论部分。该模板用于博客中的单篇文章等页面。

提示
请参考 Dawn 中的文章模板及其主要分区,以了解实施示例。

位置

文章模板位于主题的模板目录中:

└── theme
    ├── layout
    ├── templates
    |   ├── 404.json
    |   ├── article.json
    |   ...
    ...

文章对象

您可以访问 Liquid 文章对象来显示文章详情。

评论表单


评论表单可通过 Liquid form tag 和 “new_comment “,以及文章参数添加。在form tag块中,您需要包含以下内容

input类型name
Nametextcomment[author]
Emailemailcomment[email]
Commenttextareacomment[body]

例如

{% form 'new_comment', article %}
  {{ form.errors | default_errors }}

  <div class="name">
    <label for="name">Name</label>
    <input type="text" name="comment[author]" value="{{ form.author }}">
  </div>

  <div class="email">
    <label for="email">Email</label>
    <input type="email" name="comment[email]" value="{{ form.email }}">
  </div>

  <div class="comment">
    <label for="comment">Comment</label>
    <textarea name="comment[body]">{{ form.body }}</textarea>
  </div>

  <div class="submit">
    <input type="submit" value="Post">
  </div>
{% endform %}

提示
当客户发表评论时,您的代码应提供反馈,说明是否成功发表,或是否有任何错误。

应用

使用文章模板时,应熟悉文章评论的分页。

提示
如果您使用的是 JSON 模板,那么任何 HTML 或 Liquid 代码都需要包含在模板引用的分区中。

文章分页

文章评论可通过文章对象访问,每页限制为 50 条。因此,应将评论分页,以确保它们都能被访问:

{% paginate article.comments by 20 %}
  {% for comment in article.comments %}
    <!-- comment info -->
  {% endfor %}

  {{ paginate | default_pagination }}
{% endpaginate %}

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注