Creating Themes
FearlessCMS uses a simple but powerful theme system that allows you to create custom themes with HTML templates, CSS styling, and optional theme options. This guide will walk you through creating a complete theme from scratch.
Table of Contents
- Theme Structure
- Required Files
- Template System
- Template Variables
- Theme Options
- Theme Thumbnails
- CSS and Styling
- Example: Creating a Simple Theme
- Advanced Features
- Best Practices
Theme Structure
A FearlessCMS theme consists of the following directory structure:
themes/
└── your-theme-name/
├── templates/
│ ├── home.html # Page template
│ ├── page.html # Page template
│ ├── blog.html # Page template
│ ├── 404.html # Page template
│ ├── header.html.mod # Module file
│ ├── footer.html.mod # Module file
│ ├── head.html.mod # Module file
│ └── sidebar.html.mod # Module file
├── assets/
│ ├── style.css
│ ├── images/
│ └── js/
├── config.json # Theme configuration
├── thumbnail.png # Theme preview image (optional)
└── README.md # Documentation
Required Files
1. theme.json
This is the main theme configuration file that defines your theme's metadata:
json
{
"name": "Your Theme Name",
"description": "A brief description of your theme",
"version": "1.0.0",
"author": "Your Name",
"license": "MIT",
"templates": {
"home": "home.html",
"page": "page.html",
"blog": "blog.html",
"404": "404.html"
}
}
2. Templates
You need at least these page template files in the templates/
directory:
Note: Page templates use the .html
extension and will appear as template options in the admin interface when creating or editing content.
Page Templates vs Modules
Page Templates (.html
extension):
page.html
, home.html
, 404.html
, blog.html
Module Files (.html.mod
extension):
header.html.mod
, footer.html.mod
, sidebar.html.mod
Template System
FearlessCMS uses a simple template system with variable substitution and conditional logic. Templates are written in HTML with special syntax for dynamic content.
Basic Template Syntax
html
{{title}}
{{siteName}}
Fast and Fearless Content Managment
{{content}}
Template Variables
FearlessCMS provides several built-in variables you can use in your templates:
#### Global Variables
{{siteName}}
- Site name from configFast and Fearless Content Managment
- Site description/tagline{{theme}}
- Current theme name2025
- Current year{{baseUrl}}
- Base URL of the site#### Page-Specific Variables
{{title}}
- Page title{{content}}
- Page content (HTML){{url}}
- Current page URL{{parent}}
- Parent page (if any){{children}}
- Child pages (if any)#### Menu Variables
{{menu.main}}
- Main menu items{{menu.footer}}
- Footer menu items#### Theme Options
{{themeOptions.key}}
- Custom theme optionsConditional Logic
You can use conditional statements in your templates:
html
{{#if title}}
{{title}}
{{/if}}{{#if children}}
{{#each children}}
- {{title}}
{{/each}}
{{/if}}{{#if themeOptions.showSidebar}}
{{/if}}
Loops
Use loops to iterate over arrays:
html
{{#each menu.main}}
{{title}}
{{/each}}{{#each themeOptions.socialLinks}}
{{name}}
{{/each}}
Modular Templates
FearlessCMS supports modular templates, allowing you to break down your templates into reusable components. This makes themes more maintainable and reduces code duplication.
Using Modular Templates
Instead of having everything in one large template file, you can break it into smaller, reusable modules:
html
{{module=head.html}}
{{module=header.html}}
{{module=hero-banner.html}}
{{module=sidebar.html}}
{{module=footer.html}}
Creating Module Files
Create separate files for each component in your theme's templates/
directory. Important: Module files should use the .html.mod
extension to prevent them from appearing as page template options in the admin interface.
head.html.mod:
html
{{title}} - {{siteName}}
header.html.mod:
html
{{siteName}}
{{#if siteDescription}}
Fast and Fearless Content Managment
{{/if}}
footer.html.mod:
html
Module File Naming Convention
.html.mod
extension for all module files (e.g., header.html.mod
, footer.html.mod
).html
extension (e.g., page.html
, home.html
, 404.html
){{module=header.html}}
(without the .mod
extension)Module Features
.html
and .html.mod
extensions.html.mod
files are excluded from page template selectionBenefits of Modular Templates
For detailed information about modular templates, see the Modular Templates Guide.
Theme Options
You can add custom theme options that users can configure through the admin panel. Create a config.json
file in your theme directory:
json
{
"options": {
"logo": {
"type": "image",
"label": "Logo Image",
"description": "Upload your site logo"
},
"herobanner": {
"type": "image",
"label": "Hero Banner",
"description": "Hero banner image for homepage"
},
"primaryColor": {
"type": "select",
"label": "Primary Color",
"options": [
{"value": "blue", "label": "Blue"},
{"value": "green", "label": "Green"},
{"value": "red", "label": "Red"}
],
"default": "blue"
},
"showSidebar": {
"type": "checkbox",
"label": "Show Sidebar",
"default": true
}
}
}
Accessing Theme Options in Templates
html
{{#if themeOptions.logo}}
{{/if}}
{{#if themeOptions.showSidebar}}
{{/if}}
Theme Thumbnails
Theme thumbnails provide visual previews of your theme in the admin panel, making it easier for users to identify and select themes before activation. This feature enhances the user experience by showing what each theme looks like.
Adding Thumbnails to Your Theme
To add a thumbnail to your theme, simply place an image file in your theme's root directory with one of these filenames:
thumbnail.png
(preferred)thumbnail.jpg
screenshot.png
screenshot.jpg
The system will automatically detect and display the first available thumbnail file.
Thumbnail Specifications
#### File Requirements
config.json
)#### Visual Guidelines
Creating Effective Thumbnails
#### Step-by-Step Process
thumbnail.png
in your theme's root directory
- Test in the admin panel to ensure it displays correctlyBest Practices for Thumbnails
#### Photography Tips
#### Technical Considerations
Thumbnail Display Features
The admin panel provides several features for thumbnail display:
#### Visual Layout
#### Fallback Display When no thumbnail is available, the system shows:
Theme Examples by Type
#### Modern/Minimal Themes
#### Dark Themes
#### Portfolio Themes
#### Blog Themes
Troubleshooting Thumbnails
#### Thumbnail Not Displaying
#### Quality Issues
#### File Size Problems
Integration with Admin Panel
The thumbnail system integrates seamlessly with the existing admin interface:
CSS and Styling
Create your CSS file in the assets/
directory. You can use any CSS features including:
Example CSS Structure
css
/ Reset and base styles /
{
margin: 0;
padding: 0;
box-sizing: border-box;
}body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
line-height: 1.6;
color: #333;
}
/
Layout /
.container {
max-width: 1200px;
margin: 0 auto;
padding: 0 20px;
}/
Header /
header {
background: #f8f9fa;
padding: 2rem 0;
border-bottom: 1px solid #e9ecef;
}/
Navigation /
nav {
display: flex;
justify-content: space-between;
align-items: center;
}nav ul {
display: flex;
list-style: none;
gap: 2rem;
}
/
Main content /
main {
padding: 2rem 0;
min-height: 60vh;
}/
Footer /
footer {
background: #343a40;
color: white;
padding: 2rem 0;
margin-top: auto;
}/
Responsive design /
@media (max-width: 768px) {
nav ul {
flex-direction: column;
gap: 1rem;
}
}
Example: Creating a Simple Theme
Let's create a complete example theme called "SimpleBlog":
1. Create Theme Directory
bash
mkdir -p themes/simpleblog/templates
mkdir -p themes/simpleblog/assets
2. Create theme.json
json
{
"name": "Simple Blog",
"description": "A clean and simple blog theme",
"version": "1.0.0",
"author": "Your Name",
"license": "MIT",
"templates": {
"home": "home.html",
"page": "page.html",
"blog": "blog.html",
"404": "404.html"
}
}
3. Create config.json
json
{
"options": {
"logo": {
"type": "image",
"label": "Logo",
"description": "Upload your site logo"
},
"accentColor": {
"type": "select",
"label": "Accent Color",
"options": [
{"value": "blue", "label": "Blue"},
{"value": "green", "label": "Green"},
{"value": "purple", "label": "Purple"}
],
"default": "blue"
},
"showSidebar": {
"type": "checkbox",
"label": "Show Sidebar",
"default": true
}
}
}
4. Create Templates
templates/home.html:
html
{{siteName}}
{{#if themeOptions.logo}}
{{else}}
{{siteName}}
{{/if}}
Fast and Fearless Content Managment
{{content}}
{{#if themeOptions.showSidebar}}
{{/if}}
templates/page.html:
html
{{title}} - {{siteName}}
{{title}}
{{content}}
5. Add a Thumbnail
Create a thumbnail image showing your theme's appearance:
thumbnail.png
in the theme root directory6. Create CSS
assets/style.css:
css
:root {
--accent-color: #007bff;
--text-color: #333;
--bg-color: #fff;
--border-color: #e9ecef;
} {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
line-height: 1.6;
color: var(--text-color);
background: var(--bg-color);
}
.container {
max-width: 1200px;
margin: 0 auto;
padding: 0 20px;
}
header {
background: #f8f9fa;
padding: 2rem 0;
border-bottom: 1px solid var(--border-color);
}
.logo {
max-height: 60px;
width: auto;
}
main {
padding: 2rem 0;
min-height: 60vh;
}
.content-area {
display: grid;
grid-template-columns: 1fr 300px;
gap: 2rem;
}
.sidebar {
background: #f8f9fa;
padding: 1.5rem;
border-radius: 8px;
}
.post-preview {
margin-bottom: 1.5rem;
padding-bottom: 1.5rem;
border-bottom: 1px solid var(--border-color);
}
.post-preview:last-child {
border-bottom: none;
}
footer {
background: #343a40;
color: white;
padding: 2rem 0;
margin-top: auto;
}
/ Responsive /
@media (max-width: 768px) {
.content-area {
grid-template-columns: 1fr;
}
}
Advanced Features
Custom Template Functions
You can extend the template system by adding custom functions to the TemplateRenderer class.
Dynamic Menus
Menus are automatically generated from your content structure and can be customized in the admin panel.
SEO Optimization
Templates automatically include meta tags and structured data for better SEO.
Best Practices
File Naming Conventions
CSS Organization
Next Steps
Once you've created your theme:
For more advanced theme development, check out the existing themes in the themes/
directory for examples and inspiration.
Breadcrumb Navigation
Breadcrumbs help users understand their location within your site. Here's a simple implementation:
html
Basic CSS for breadcrumbs:
css
.breadcrumb {
background: #f8f9fa;
padding: 0.75rem 1rem;
border-radius: 6px;
margin-bottom: 2rem;
font-size: 0.9rem;
}
.breadcrumb a {
color: #007bff;
text-decoration: none;
}
.breadcrumb a:hover {
text-decoration: underline;
}
.breadcrumb .current-page {
color: #6c757d;
font-weight: 500;
}
For more advanced breadcrumb implementations and dark mode support, see the Template Reference.