# components/article_card

> Thẻ bài viết: ảnh, ngày đăng, tiêu đề, tóm tắt. Dùng trong section Bài viết nổi bật, Danh sách bài viết, Nội dung bài viết.

Thẻ bài viết: ảnh, ngày đăng, tiêu đề, tóm tắt. Dùng trong section Bài viết nổi bật, Danh sách bài viết, Nội dung bài viết.

- **Tệp giao diện:** `components/article_card.html`

## Biến đầu vào

Component đọc biến có sẵn tại chỗ chèn. Những biến dưới đây phải tồn tại, nếu không component sẽ dựng ra khối rỗng.

| Biến | Kiểu | Bắt buộc | Mô tả |
|---|---|---|---|
| `article` | [`Article`](/docs/doi-tuong/article/index.md) | có | Bài viết cần hiển thị; lấy từ biến vòng lặp {% for article in ... %}. |

## Cách chèn

```liquid
{% for article in articles %}
  {% include 'components/article_card' %}
{% endfor %}
```

Đường dẫn trong `{% include %}` tính từ gốc bộ giao diện và **không có đuôi `.html`**.

## Mã đầy đủ

Toàn bộ tệp `components/article_card.html` của bộ giao diện mặc định.

```liquid
{%- comment -%}Thẻ bài viết. Biến vào: article; tuỳ chọn ss.show_date / ss.show_summary (mặc định hiện).{%- endcomment -%}
<article class="article-card">
  {%- if article.url -%}<a href="{{ article.url | escape }}" class="article-card__media" tabindex="-1" aria-hidden="true">{%- else -%}<span class="article-card__media">{%- endif -%}
    {%- if article.thumbnail_url -%}<img src="{{ article.thumbnail_url | escape }}" alt="" width="640" height="400" loading="lazy" decoding="async">{%- else -%}{{ 'image' | placeholder_svg: 'placeholder-svg' }}{%- endif -%}
  {%- if article.url -%}</a>{%- else -%}</span>{%- endif -%}
  <div class="article-card__body">
    {%- if ss.show_date != false and article.published_at -%}<p class="article-card__date"><time datetime="{{ article.published_at | slice: 0, 10 | escape }}">{{ article.published_at | date_vi }}</time></p>{%- endif -%}
    <h3 class="article-card__title">{% if article.url %}<a href="{{ article.url | escape }}">{{ article.title | escape }}</a>{% else %}{{ article.title | escape }}{% endif %}</h3>
    {%- if ss.show_summary != false and article.summary -%}<p class="article-card__summary">{{ article.summary | strip_html | truncate: 140 | escape }}</p>{%- endif -%}
  </div>
</article>
```

## Dùng ở

_Chưa có mục nào._

## Trường được dùng

Component chỉ đọc những trường này của [`Article`](/docs/doi-tuong/article/index.md). Sửa component để đọc thêm trường khác thì nhớ cập nhật `catalog/components.yaml`.

- `article.url`
- `article.thumbnail_url`
- `article.published_at`
- `article.title`
- `article.summary`
