oCMS features a powerful and flexible theme system. This guide covers everything you need to create custom themes.
Theme Structure
A theme consists of templates, static assets, and optional translations:
mytheme/
├── theme.json # Theme metadata
├── templates/
│ ├── layouts/
│ │ └── base.html # Main layout
│ ├── pages/
│ │ ├── home.html
│ │ ├── page.html
│ │ └── post.html
│ └── partials/
│ ├── header.html
│ └── footer.html
├── static/
│ ├── css/
│ └── js/
└── locales/ # Optional translations
Template Inheritance
oCMS uses Go's html/template with a block-based inheritance system:
{{/* base.html */}}
<html>
<head>
{{block "head" .}}{{end}}
</head>
<body>
{{block "content" .}}{{end}}
</body>
</html>
Template Functions
oCMS provides many helper functions:
T- Translation functionTTheme- Theme-specific translationsFormatDate- Date formattingSafeHTML- Render trusted HTMLTruncate- Text truncation
Static Assets
Place CSS, JavaScript, and images in the static/ directory. Reference them in templates using the asset path.
Best Practices
- Use semantic HTML for accessibility
- Optimize images before including them
- Minimize CSS and JavaScript
- Test responsive layouts thoroughly
- Support both light and dark modes