xStore.pages

Trang nội dung tĩnh (giới thiệu, chính sách…) và biến tuỳ chỉnh của cửa hàng.

Phương thức

Phương thức Cú pháp Mô tả Từ phiên bản
get xStore.pages.get(pageId): Promise<CmsPage> Trang nội dung theo id. 2.1
getBySlug xStore.pages.getBySlug(slug): Promise<CmsPage> Trang nội dung theo slug. 2.1
customVariables xStore.pages.customVariables(): Promise<CursorPaginatedResponse<CustomVariable>> Biến tuỳ chỉnh do chủ cửa hàng khai báo (slug → value). Dữ liệu tham chiếu có giới hạn; lấy một lần mỗi lần dựng trang. 2.1

Ví dụ đầy đủ

<script>
  // Trang tĩnh tra theo slug — cùng slug xuất hiện trên URL.
  async function renderPage(slug) {
    const tr = await xStore.pages.getBySlug(slug);
    document.title = tr.meta_title || tr.title;
    document.getElementById('page-title').textContent = tr.title;
  }

  // Biến tuỳ chỉnh: số điện thoại, link Zalo, dòng chân trang…
  // Dữ liệu tham chiếu có giới hạn — lấy MỘT lần rồi dùng lại cho cả trang.
  async function renderContactInfo() {
    const bt = await xStore.pages.customVariables();
    const map = Object.fromEntries(bt.items.map((v) => [v.slug, v.value]));

    document.getElementById('hotline').textContent = map.hotline ?? '';
    document.getElementById('zalo').href = map.zalo_url ?? '#';
  }

  renderContactInfo();
</script>

Thư viện gọi tới /api/... trên chính tên miền cửa hàng, nên không cần khai báo địa chỉ máy chủ ở bất kỳ đâu.

Xem thêm Sự kiện để giao diện tự cập nhật sau mỗi thao tác.