The templates system provides full-page UI patterns and complete application layouts. The goal is to mirror shadcn/ui's blocks system implementation patterns. Templates are pre-built, production-ready page layouts that can be copied and customized for rapid application development.
Migration Goal: This system is being aligned to closely follow the shadcn/ui v4 blocks implementation patterns while preserving the current PageHeader and TabsNav UI components.
src/app/[lang]/(root)/templates/ # Template showcase routes
├── [...categories]/ # Dynamic category routes (catch-all)
│ └── page.tsx # Template detail page
├── page.tsx # Templates listing page
└── ../view/templates/
└── [name]/page.tsx # Template preview (iframe)
src/components/root/template/ # Template system core
├── index.ts # Main registry export
├── config.ts # Template configurations
├── content.tsx # Server component container
├── hero.tsx # Hero section with PageHeader
├── templates-nav.tsx # Navigation matching BlocksNav
├── all.tsx # Template grid display
├── template-display.tsx # Template display with caching
├── template-viewer.tsx # Complex viewer with context
├── registry.ts # Zod schemas
├── registry-templates.ts # Template definitions
└── __registry__/ # Generated registry index
├── index.tsx # Registry export
└── __templates__.json # Template metadata
src/lib/ # Helper functions
├── categories.ts # Category definitions (moved from registry)
└── templates.ts # Template helper functions (getAllTemplateIds, etc.)
src/components/template/ # Individual template components
├── hero-01/ # Hero section template
│ └── page.tsx
├── header-01/ # Header template
├── sidebar-01/ # Sidebar template
├── login-01/ # Login template
└── footer-01/ # Footer template
src/registry/ # Template registry (legacy structure)
├── new-york/templates/ # New York style templates
└── default/templates/ # Default style templates
/[lang]/templates - Shows all templates in a grid/[lang]/templates/[...categories] - Catch-all route for template details/[lang]/view/templates/[name] - Isolated preview pagegenerateStaticParams() for static generationname, type, description, files, categories, metaPageHeader atom component (to be preserved)templates/page.tsx
↓
TemplateContent (server)
↓
├─→ Hero (PageHeader)
├─→ TemplateTabs (TabsNav)
└─→ TemplateDisplay (async)
↓
getTemplate()
↓
TemplateViewer (client)
├─→ Toolbar
├─→ Preview (iframe)
└─→ Code Display
| Aspect | Your Templates | shadcn/ui Blocks | Status |
|---|---|---|---|
| Main Page | /templates/page.tsx | /blocks/page.tsx | ✅ Same pattern |
| Dynamic Route | /templates/[...categories]/page.tsx | /blocks/[...categories]/page.tsx | ✅ Identical! |
| Preview Route | /view/templates/[name]/page.tsx | N/A - uses inline preview | ⚠️ Different |
| Static Generation | generateStaticParams() | generateStaticParams() | ✅ Same |
| Route Params | params: { categories: string[] } | params: { categories?: string[] } | ✅ Similar |
Key Finding: shadcn/ui blocks ALSO uses
[...categories]catch-all routing! Your implementation is already aligned.
| Component | Your Templates | shadcn/ui Blocks | Alignment Needed |
|---|---|---|---|
| Layout File | No dedicated layout.tsx | layout.tsx with PageHeader | ❌ Add layout |
| Page Header | In content.tsx via Hero component | In layout.tsx | ⚠️ Move to layout |
| Navigation | TemplateTabs component | BlocksNav in PageNav | ✅ Similar pattern |
| Container | Custom wrapper | container-wrapper + container | ⚠️ Align classes |
| Component | Your Implementation | shadcn/ui Implementation | Notes |
|---|---|---|---|
| Main Display | TemplateDisplay → TemplateViewer | BlockDisplay → BlockViewer | ✅ Same pattern |
| Server/Client Split | ✅ Server component fetches, client renders | ✅ Same approach | ✅ Aligned |
| Preview | TemplateViewerView (iframe) | ComponentPreview (direct) | ⚠️ Different approach |
| Code Display | TemplateViewerCode with file tree | Highlighted code in BlockViewer | ✅ Similar |
| Toolbar | TemplateViewerToolbar | Part of BlockViewer | ✅ Similar |
| Aspect | Your Templates | shadcn/ui Blocks |
|---|---|---|
| Registry Location | registry-templates.ts | registry/__index__.tsx |
| Registry Format | Array of objects | Index object with style keys |
| Metadata | In registry objects | __blocks__.json for metadata |
| Categories | registry-categories.ts | lib/categories.ts |
| Schema Validation | Zod schemas | Zod schemas (registryItemSchema) |
# Your Templates Structure:
src/
├── app/[lang]/(root)/templates/
│ ├── page.tsx
│ └── [...categories]/page.tsx
├── components/
│ ├── root/template/
│ │ ├── registry-templates.ts
│ │ ├── template-viewer.tsx
│ │ └── ...
│ └── template/
│ ├── hero-01/
│ └── ...
# shadcn/ui Blocks Structure:
apps/v4/
├── app/(app)/blocks/
│ ├── page.tsx
│ ├── [...categories]/page.tsx
│ └── layout.tsx
├── components/
│ ├── block-display.tsx
│ ├── block-viewer.tsx
│ └── blocks-nav.tsx
├── lib/
│ ├── blocks.ts
│ └── categories.ts
└── registry/
├── __index__.tsx
└── __blocks__.json
| Function | Your Templates | shadcn/ui Blocks |
|---|---|---|
| Get Items | getTemplate() / getRegistryItem() | getRegistryItem() |
| Get All Items | Custom logic | getAllBlockIds() / getAllBlocks() |
| Highlight Code | highlightCode() | highlightCode() |
| File Tree | Custom implementation | createFileTreeForRegistryItemFiles() |
| Caching | Not visible | React.cache() wrapper functions |
| Aspect | Your Templates | shadcn/ui Blocks |
|---|---|---|
| Featured List | FEATURED_TEMPLATES in config | FEATURED_BLOCKS in page.tsx |
| Display Method | Grid with categories | Sequential BlockDisplay components |
| Browse Link | Via tabs | Button to /blocks/sidebar |
[...categories] pattern matches shadcn/ui exactly!Create src/app/[lang]/(root)/templates/layout.tsx:
// Move PageHeader and navigation to layout
export default function TemplatesLayout({ children }) {
return (
<>
<PageHeader>
<Announcement />
<PageHeaderHeading>Templates title</PageHeaderHeading>
<PageHeaderDescription>Description</PageHeaderDescription>
<PageActions>...</PageActions>
</PageHeader>
<PageNav>
<TemplatesNav />
</PageNav>
<div className="container-wrapper">
<div className="container">{children}</div>
</div>
</>
)
}TemplateDisplay → follow BlockDisplay patternTemplateViewer complexity__templates__.json for metadataReact.cache() for performanceCreate lib/templates.ts similar to lib/blocks.ts:
export async function getAllTemplateIds()
export async function getAllTemplates()Align TemplateTabs with BlocksNav pattern while keeping your UI style
PageHeader atom component (it's similar to shadcn's)TabsNav for navigation (just align the data flow)Templates are full React components with complete layouts:
registry-*.ts filesnpx shadcn add template-nameNote: This process is being updated to align with shadcn/ui blocks patterns. The following describes the current implementation.
Create your template in src/components/template/your-template/:
// src/components/template/your-template/page.tsx
import { Button } from "@/components/ui/button"
import { Card } from "@/components/ui/card"
export default function YourTemplate() {
return (
<div className="container mx-auto p-6">
<header className="mb-8">
<h1 className="text-4xl font-bold">Your Template</h1>
<p className="text-muted-foreground">
Template description here
</p>
</header>
<main className="grid gap-6">
<Card className="p-6">
<h2 className="text-2xl font-semibold mb-4">
Section Title
</h2>
<p>Your content here</p>
<Button className="mt-4">Action</Button>
</Card>
</main>
</div>
)
}Add to src/components/root/template/registry-templates.ts:
// src/components/root/template/registry-templates.ts
export const templates: Registry = [
{
name: "your-template",
type: "registry:template",
description: "Your template description",
files: [
{
path: "templates/your-template/page.tsx",
type: "registry:page",
},
],
dependencies: ["@/components/ui/button", "@/components/ui/card"],
registryDependencies: ["button", "card"],
categories: ["landing"],
meta: {
iframeHeight: "900px",
containerClassName: "w-full",
},
},
// ... other templates
]Update src/components/root/template/config.ts:
// src/components/root/template/config.ts
export const TEMPLATES: Template[] = [
{
name: "your-template",
type: "registry:template",
description: "Your template description",
categories: ["landing"],
},
// ... other templates
]If needed, update the display configuration in src/components/root/template/all.tsx or relevant display files.
# If using registry build process
pnpm build:registryComplete landing page layouts:
User authentication interfaces:
Admin and user dashboards:
Core app structures:
Marketing and content pages:
All templates include:
Templates work with:
Built-in a11y features:
Templates include:
Each template generates a JSON file:
{
"$schema": "https://ui.shadcn.com/schema.json",
"name": "dashboard-01",
"type": "registry:template",
"description": "A dashboard layout with sidebar navigation",
"files": [
{
"path": "templates/dashboard-01/page.tsx",
"content": "// Full component code here",
"type": "registry:page",
"target": "app/dashboard/page.tsx"
}
],
"dependencies": [
"@radix-ui/react-icons",
"@tanstack/react-table"
],
"registryDependencies": [
"button",
"card",
"table"
],
"categories": ["application"],
"subcategory": "dashboard"
}Templates installable via:
# Install a specific template
npx shadcn add dashboard-01
# Install with custom path
npx shadcn add dashboard-01 --path app/admin
# Install with dependencies
npx shadcn add dashboard-01 --depsTemplates support multiple styles:
Style-specific imports are automatically adjusted.
After installation, templates can be:
Extend templates with new sections:
import OriginalTemplate from "./dashboard-01/page"
import { CustomSection } from "./custom-section"
export default function ExtendedDashboard() {
return (
<>
<OriginalTemplate />
<CustomSection />
</>
)
}Apply custom themes:
/* Override template variables */
.template-dashboard {
--template-bg: var(--custom-bg);
--template-border: var(--custom-border);
--template-text: var(--custom-text);
}# Clear build cache
rm -rf .next __registry__
# Rebuild registry
pnpm build:registry
# Restart dev server
pnpm devConnect templates to your data:
// Transform static template to dynamic
export default async function DashboardPage() {
const data = await fetchDashboardData()
return <DashboardTemplate data={data} />
}Add i18n to templates:
import { useTranslation } from "@/lib/i18n"
export default function LocalizedTemplate() {
const { t } = useTranslation()
return (
<h1>{t("template.title")}</h1>
)
}Integrate with state libraries:
import { useStore } from "@/lib/store"
export default function StatefulTemplate() {
const { state, actions } = useStore()
return <TemplateWithState {...state} {...actions} />
}Submit templates via:
The templates system has been successfully migrated to mirror the shadcn/ui v4 blocks implementation pattern.
✅ Navigation: Renamed to templates-nav.tsx matching BlocksNav pattern
✅ Categories: Moved to lib/categories.ts matching blocks structure
✅ Helper Functions: Created lib/templates.ts with getAllTemplateIds() and getAllTemplates()
✅ Cache Optimization: Added React.cache() wrappers for performance
✅ Static Exports: Added dynamic = "force-static" and revalidate = false
✅ Category Routing: Updated [...categories] page to use getAllTemplateIds()
✅ Container Classes: Added container-wrapper, section-soft, and border-grid
✅ Metadata File: Created __templates__.json matching __blocks__.json pattern
✅ Imports Updated: All imports now use new locations
✅ Current page structure (no layout.tsx changes)
✅ Hero component in content.tsx
✅ PageHeader atom component
✅ Current routing structure [...categories]
✅ TemplateViewer with iframe approach
✅ Theme system and styling
src/components/root/template/src/components/template/src/app/[lang]/(root)/templates/C:\Users\pc\Downloads\ui-main\ui-main\apps\v4\app\(app)\blocks\ (local copy for reference)On This Page
Templates FactoryOverviewCurrent ArchitectureFile StructureCurrent Implementation DetailsRouting PatternRegistry SystemDisplay ComponentsData FlowSide-by-Side Comparison: Templates vs shadcn/ui Blocks1. Routing Structure2. Layout Structure3. Display Components4. Registry System5. Code Organization6. Key Functions & Data Flow7. Featured Items DisplayAlignment Recommendations✅ What's Already Aligned🔄 Changes Needed for Full Alignment1. Add Layout File2. Simplify Display Components3. Align Registry Structure4. Add Helper Functions5. Update Navigation Component🎯 Components to Keep As-IsHow It Works1. Template Definition2. Registry System3. Showcase Pages4. CLI IntegrationHow to Add New Templates (Current Process)Step 1: Create Template ComponentStep 2: Register TemplateStep 3: Add to ConfigStep 4: Update Display ComponentsStep 5: Generate Registry (if applicable)Template CategoriesLanding PagesAuthenticationDashboardsApplication LayoutsMarketingTemplate FeaturesResponsive DesignTheme SupportAccessibilityProduction ReadyRegistry SystemJSON StructureCLI ConsumptionStyle VariantsBest Practices1. Template Structure2. Component Usage3. Documentation4. Performance5. TestingCustomizationModifying TemplatesAdding SectionsTheming TemplatesTroubleshootingBuild IssuesImport ErrorsStyling ProblemsRegistry UpdatesAdvanced FeaturesDynamic Data IntegrationMulti-Language SupportState ManagementPerformanceOptimization StrategiesMetricsFuture EnhancementsPlanned FeaturesCommunity TemplatesMigration Status✅ Migration Complete: Templates Now Mirror shadcn/ui BlocksCompleted Migration TasksWhat's Preserved (As Requested)Resourcesshadcn/ui ReferencesLocal References