# cms/article

> Trang chi tiết một bài viết.

Trang chi tiết một bài viết.

- **Tệp giao diện:** `cms/article.html`
- **Đường dẫn:** `/bai-viet/{slug}`
- **Controller:** `App\Modules\Cms\CmsController::articleDetailPage`

Ngoài những biến dưới đây, slot này còn nhận toàn bộ [biến toàn cục](/docs/bien-toan-cuc/index.md).

## Biến của trang

| Biến | Kiểu | Mô tả | Từ phiên bản |
|---|---|---|---|
| `article` | [`Article`](/docs/doi-tuong/article/index.md) | Bài viết đang xem, kèm phần thân HTML. | 1.0 |
| `article_categories` | [`ArticleCategory[]`](/docs/doi-tuong/articlecategory/index.md) | Chuyên mục của bài viết. | 1.0 |
| `related_articles` | [`Article[]`](/docs/doi-tuong/article/index.md) | Bài viết liên quan (cùng chuyên mục). | 1.0 |
| `tags` | `string[]` | Thẻ của bài viết. | 1.0 |
| `reviews` | [`Review[]`](/docs/doi-tuong/review/index.md) | Đánh giá đã duyệt của bài viết. | 1.0 |
| `view_count` | `integer` | Tổng lượt xem của bài viết, cộng dồn từ bảng thống kê theo tháng. | 1.2 |
| `recent_articles` | [`Article[]`](/docs/doi-tuong/article/index.md) | Bài viết mới nhất, dùng cho cột bên "Tin mới nhất". | 1.2 |
| `page_title` | `string` | Tiêu đề SEO của trang. | 1.0 |
| `page_description` | `string` | Mô tả SEO của trang. | 1.0 |

## Mã đầy đủ

Toàn bộ tệp `cms/article.html` của bộ giao diện mặc định. Chép về `templates/<bộ giao diện của bạn>/cms/article.html` rồi sửa theo ý muốn.

```liquid
<div class="container page-content">
  <nav class="breadcrumb">
    <a href="/">Trang chủ</a> /
    <a href="/bai-viet">Bài viết</a> /
    {% if article_categories.size > 0 %}
      <a href="/bai-viet?danh-muc={{ article_categories[0].slug | escape }}">{{ article_categories[0].title | escape }}</a> /
    {% endif %}
    <span>{{ article.title | escape }}</span>
  </nav>

  <article class="article-detail">
    <header class="article-detail__header">
      <h1 class="article-detail__title">{{ article.title | escape }}</h1>
      <div class="article-detail__meta">
        {% if article.author_name %}
          <span class="article-detail__author">{{ article.author_name | escape }}</span>
        {% endif %}
        {% if article.published_at %}
          <time class="article-detail__date">{{ article.published_at | slice: 0, 10 | escape }}</time>
        {% endif %}
        {% if article_categories.size > 0 %}
          <span class="article-detail__cats">
            {% for cat in article_categories %}
              <a href="/bai-viet?danh-muc={{ cat.slug | escape }}">{{ cat.title | escape }}</a>{% unless forloop.last %}, {% endunless %}
            {% endfor %}
          </span>
        {% endif %}
      </div>
      {% if article.thumbnail_url %}
        <img src="{{ article.thumbnail_url | escape }}" alt="{{ article.title | escape }}"
             class="article-detail__cover" loading="lazy">
      {% endif %}
    </header>

    {% if article.body %}
    <div class="rich-text article-detail__body">{{ article.body }}</div>
    {% endif %}

    {% if tags.size > 0 %}
    <div class="article-detail__tags">
      <strong>Tags:</strong>
      {% for tag in tags %}
        <span class="tag">{{ tag | escape }}</span>
      {% endfor %}
    </div>
    {% endif %}
  </article>

  {% if reviews.size > 0 %}
  <section class="pdp-reviews">
    <h2 class="section__title">Bình luận ({{ reviews.size | escape }})</h2>
    {% for review in reviews %}
    <div class="review-item">
      <div class="review-item__header">
        <strong>{{ review.reviewer_name | default: 'Ẩn danh' | escape }}</strong>
        <time>{{ review.created_at | slice: 0, 10 | escape }}</time>
      </div>
      {% if review.title %}<p class="review-item__title">{{ review.title | escape }}</p>{% endif %}
      {% if review.body %}<p class="review-item__body">{{ review.body | escape }}</p>{% endif %}
    </div>
    {% endfor %}
  </section>
  {% endif %}

  {% if related_articles.size > 0 %}
  <section class="section section--related">
    <h2 class="section__title">Bài viết liên quan</h2>
    <div class="article-grid article-grid--small">
      {% for art in related_articles %}
      {% if art.url %}<a href="{{ art.url | escape }}" class="article-card article-card--sm">{% else %}<span class="article-card article-card--sm">{% endif %}
        {% if art.thumbnail_url %}
          <img src="{{ art.thumbnail_url | escape }}" alt="{{ art.title | escape }}"
               class="article-card__img" loading="lazy">
        {% endif %}
        <div class="article-card__body">
          <h3 class="article-card__title">{{ art.title | escape }}</h3>
          <time class="article-card__date">{{ art.published_at | slice: 0, 10 | escape }}</time>
        </div>
      {% if art.url %}</a>{% else %}</span>{% endif %}
      {% endfor %}
    </div>
  </section>
  {% endif %}
</div>
```
