Bỏ qua, đến nội dung

@digiforce-nc/plugin-block-template

Plugin quản lý block template - cho phép lưu cấu hình block thành template tái sử dụng, hỗ trợ template kế thừa (inherited) và chuyển đổi qua lại giữa template và block thường.

Plugin này làm gì?

Khi admin xây dựng nhiều trang có block tương tự (cùng collection, cùng layout), việc cấu hình lại từ đầu rất tốn thời gian. Block template cho phép lưu một block đã cấu hình thành template, sau đó sử dụng lại ở nhiều nơi - thậm chí với chế độ inherited, thay đổi template sẽ tự động cập nhật tất cả block liên kết.

Ba nhiệm vụ chính

#Nhiệm vụChi tiết
1Lưu block thành templateSave cấu hình block (schema) vào bảng blockTemplates
2Template kế thừaBlock liên kết với template - thay đổi template tự cập nhật block
3Quản lý templateTrang quản lý liệt kê, xem, xóa template; hỗ trợ desktop và mobile

Kiến trúc

Tổng quan

Plugin có server (lưu trữ template, quản lý liên kết) và client (UI quản lý, decorator kế thừa):

TầngVai tròThành phần
Client UIQuản lý template, decorator kế thừaBlockTemplatePage, TemplateGridDecorator
Server APICRUD template, link/unlinkActions: saveSchema, link, destroy
DatabaseLưu template metadata + linksblockTemplates, blockTemplateLinks
UI SchemaLưu trữ schema thực tếTừ plugin-ui-schema-storage

API endpoints

EndpointMethodMô tảACL
blockTemplates:listGETLiệt kê tất cả templateloggedIn
blockTemplates:getGETLấy chi tiết templateloggedIn
blockTemplates:saveSchemaPOSTLưu block schema thành templateloggedIn
blockTemplates:linkPOSTLiên kết block với template (inherited)loggedIn
blockTemplates:destroyDELETEXóa templateloggedIn

Middleware

MiddlewareVai trò
templateDataMiddlewareInject dữ liệu template vào request context khi block sử dụng template

Luồng lưu và sử dụng template

Database

Bảng blockTemplates

CộtKiểuMô tả
keystring (PK)Khóa duy nhất của template
titlestringTên hiển thị template
descriptiontextMô tả template
typestringLoại: form, details, table, ...
collectionstringCollection liên kết
dataSourcestringData source
componentTypestringLoại component
menuNamestringTên menu chứa template
configuredbooleanĐã cấu hình xong chưa

Quan hệ: belongsTo uiSchema - template trỏ đến schema đã lưu.

CộtKiểuMô tả
iduid (PK)Định danh
templateKeystring (FK)Trỏ đến blockTemplates.key
uiSchemaUidstring (FK)Trỏ đến uiSchema đang dùng template

Tính năng

Tính năngMô tả
Save as templateLưu block hiện tại thành template tái sử dụng
Inherited templateBlock liên kết - thay đổi template cập nhật tất cả
Duplicate templateTạo bản sao độc lập từ template
Mobile templateHỗ trợ template cho mobile layout
Template managerTrang quản lý với danh sách, preview, delete
ConvertChuyển block thường thành template và ngược lại

Thành phần client

Thành phầnMô tả
BlockTemplatePageTrang quản lý template (Settings > Block Templates)
BlockTemplateListDanh sách template với filter theo type
TemplateGridDecoratorDecorator cho block kế thừa, hiển thị badge "Template"
BlockTemplateMenusProviderProvider cung cấp template vào menu "Add block"
BlockTemplateDesignerDesigner cho template: rename, convert, unlink

Dependencies

PackageVai trò
@digiforce-nc/clientClient framework (peer)
@digiforce-nc/serverServer framework (peer)
@digiforce-nc/databaseDatabase ORM (peer)
plugin-ui-schema-storageLưu trữ UI schema (peer)
plugin-mobileHỗ trợ mobile template (optional peer)

Mục lục chi tiết