Template System Documentation

CatCMS features a modern, server-side rendering template system built with TypeScript, HTMX, Alpine.js, and TailwindCSS. [object Object]

Overview

Key Features

  • Server-Side Rendering (SSR) - Fast initial page loads with full HTML from the server
  • Type-Safe Templates - Full TypeScript support for template data interfaces
  • HTMX-Driven Interactions - Dynamic updates without complex JavaScript
  • Alpine.js for Client-Side Logic - Lightweight JavaScript framework for interactivity
  • TailwindCSS Design System - Utility-first CSS with dark mode support
  • Component-Based Architecture - Reusable, composable template components

Technology Stack

πŸ“

TypeScript

Type-safe template functions

⚑

HTMX 2.0

HTML-driven interactions

πŸ”οΈ

Alpine.js 3.x

Reactive client-side logic

🎨

TailwindCSS

Utility-first styling

πŸ”₯

Hono.js

Server framework integration

🧩

Template Renderer

Handlebars-like engine


Template Architecture

Directory Structure

src/templates/
β”œβ”€β”€ layouts/                              # Page layouts
β”‚   β”œβ”€β”€ admin-layout-v2.template.ts      # Main admin layout
β”‚   β”œβ”€β”€ admin-layout-catalyst.template.ts # Catalyst-based admin UI
β”‚   └── docs-layout.template.ts          # Documentation layout
β”œβ”€β”€ pages/                                # Full page templates
β”‚   β”œβ”€β”€ admin-dashboard.template.ts      # Dashboard with stats & charts
β”‚   β”œβ”€β”€ admin-content-list.template.ts   # Content listing with filters
β”‚   β”œβ”€β”€ admin-content-edit.template.ts   # Content editor
β”‚   β”œβ”€β”€ admin-media-library.template.ts  # Media management
β”‚   β”œβ”€β”€ admin-users-list.template.ts     # User management
β”‚   └── auth-login.template.ts           # Login page
β”œβ”€β”€ components/                           # Reusable components
β”‚   β”œβ”€β”€ form.template.ts                 # Form builder
β”‚   β”œβ”€β”€ table.template.ts                # Data tables with sorting
β”‚   β”œβ”€β”€ media-grid.template.ts           # Media file grid/list
β”‚   β”œβ”€β”€ alert.template.ts                # Alert notifications
β”‚   β”œβ”€β”€ pagination.template.ts           # Pagination controls
β”‚   β”œβ”€β”€ filter-bar.template.ts           # Filter controls
β”‚   └── logo.template.ts                 # Logo component
└── utils/
    └── template-renderer.ts             # Template rendering utility

Template Function Pattern

All templates follow this TypeScript pattern:

Template Pattern


Template Structure

Three-Tier Template Hierarchy

Layout (admin-layout-v2.template.ts)
  └── Page (admin-dashboard.template.ts)
       └── Components (table.template.ts, alert.template.ts, etc.)

1. Layouts - Define the overall page structure (header, sidebar, footer)

2. Pages - Compose components into full pages

3. Components - Reusable UI elements

Template Rendering Flow

The template renderer provides Handlebars-like functionality:

Template Renderer

Renderer Features

  • Variable interpolation: {{variable}}
  • Nested properties: {{user.name}}
  • Raw HTML: {{{rawHtml}}}
  • Conditionals: {{#if condition}}...{{/if}}
  • Loops: {{#each array}}...{{/each}}
  • Special loop variables: {{@index}}, {{@first}}, {{@last}}
  • Helper functions: {{titleCase field}}

Layout System

Admin Layout v2 (with Catalyst)

The main admin layout delegates to Catalyst UI:

Admin Layout Interface

Layout Features

1. Responsive Sidebar Navigation

  • Dashboard, Content, Collections, Media, Users, Plugins, Cache, Design, Logs, Settings
  • Dynamic menu items from plugins
  • Active state highlighting

2. Top Bar

  • Logo with customizable size/variant
  • Notifications button
  • Background theme customizer
  • User dropdown menu

3. Background Customization

  • Multiple gradient themes (Deep Space, Cosmic Blue, Matrix Green, Cyber Pink)
  • Custom PNG backgrounds (Blue Waves, Stars, Crescent, 3D Waves)
  • Darkness adjustment slider
  • Persisted to localStorage

4. Dark Mode Support

  • Class-based dark mode (dark: prefix)
  • System preference detection
  • Toggle functionality with localStorage persistence

Component Library

1. Form Component

Form Builder

Supported Field Types: text, email, number, date, textarea, rich_text (with EasyMDE), select, multi_select, checkbox, file

2. Table Component

Data Table

Table Features: Column sorting (string, number, date, boolean), row selection with β€œselect all”, clickable rows, empty state, custom cell rendering

3. Alert Component

Alert Notifications

Alert Types: success, error, warning, info

4. Pagination Component

Pagination

Pagination Features: Page number navigation, previous/next buttons, page size selector, query parameter preservation, mobile-responsive


HTMX Integration

HTMX enables dynamic, server-driven interactions without writing JavaScript.

Core HTMX Patterns

Auto-Refresh with Polling

Form Submission

Delete with Confirmation

HTMX Attributes Reference

AttributePurposeExample
hx-getGET requesthx-get="/api/data"
hx-postPOST requesthx-post="/api/create"
hx-putPUT requesthx-put="/api/update/123"
hx-deleteDELETE requesthx-delete="/api/delete/123"
hx-targetWhere to insert responsehx-target="#result"
hx-swapHow to insertinnerHTML, outerHTML, beforeend
hx-triggerWhen to triggerclick, load, change, every 30s
hx-indicatorLoading indicatorhx-indicator="#spinner"
hx-confirmConfirmation dialoghx-confirm="Are you sure?"

Alpine.js Integration

Alpine.js provides reactive client-side interactions.

Alpine.js Examples

Dropdown Menu

Tabs


TailwindCSS & Design System

TailwindCSS Configuration

CatCMS uses Tailwind via CDN with custom configuration:

Tailwind Config

Common Utility Patterns

Form Inputs

Buttons


Dark Mode Implementation

Dark Mode Toggle

Dark mode uses Tailwind’s class strategy:

Dark Mode Toggle

Dark Mode Utilities

Every component uses dark mode variants:

Dark Mode Variants


Creating Custom Templates

Step-by-Step Guide

Step 1: Define Data Interface

Step 2: Create Component

Step 3: Create Page Template

Step 4: Create Route Handler

Template Best Practices

  • Always define TypeScript interfaces for template data - Break down complex UIs into reusable components - Include ARIA attributes and semantic HTML for accessibility - Always escape user-provided content to prevent XSS - Use HTMX for partial updates instead of full page reloads - Provide fallback UI and error states - Always provide loading skeletons

Next Steps

Was this page helpful?