Tham khảo Lập trình viên
Razor helpers, site context, CSS architecture
Tham khảo Lập trình viên — Helpers & Extensions
uTPro cung cấp bộ Razor/C# helpers dùng trong các views. Thêm @using uTPro.Extension; khi cần.
Current Site & Item Context
ICurrentSiteExtension (inject như CurrentSite) cung cấp context theo request:
CurrentSite.GetItem()— các node chính (Root, FolderSettings, PageHome, Current, PageErrors)CurrentCulture/DefaultCulture— culture hiện tại và mặc địnhGetCultures()— tất cả cultures đã publishGetDictionaryValue(key)— tra cứu dictionary translation
Content Inheritance
ContentExtensions phân giải giá trị kế thừa xuống cây (self → ancestors) với cache theo request. Dùng cho topComponent/bottomComponent cascading.
Media & Responsive Images
ResponsiveImg(...) render responsive img (WebP + srcset). Tham số chính: alt, cssClass, sizes, priority (LCP), quality (mặc định 80).
ValueToMediaDesktop/Tablet/Mobile trả về URL media đã resize (2048/1500/800).
HTML & String Helpers
| Helper | Mục đích |
|---|---|
ToHtml() | Render HTML từ CMS với sanitization |
ToInline() | Gộp newlines thành spaces |
LinkToString() | URL an toàn từ Umbraco Link |
CSS Architecture
CSS theo quy ước trong wwwroot/css/{SiteName}/:
- variables.css — Design tokens (tất cả màu)
- critical.css — Inline trong head
- layout.css — Reset + grid + typography
- main.css — Components + responsive
- Components/ — CSS file theo component
Mỗi component có CSS file tương ứng đăng ký qua SetSection. CSS chỉ load khi component xuất hiện trên trang.
Block Preview Aware Components
Components phát hiện chế độ preview qua Context.Request.IsBlockPreviewRequest() và chỉ render CSS (không JS) trong preview.