Theme Options Guide

This guide explains how to implement and use theme options in FearlessCMS, allowing users to customize themes through the admin panel.

Overview

Theme options allow you to make your themes configurable without requiring users to edit code. Users can customize colors, upload images, toggle features, and more through a user-friendly interface.

Creating Theme Options

1. Define Options in config.json

Create a config.json file in your theme directory to define available options:

json
{
    "options": {
        "logo": {
            "type": "image",
            "label": "Logo Image",
            "description": "Upload your site logo (recommended: 200x60px)"
        },
        "herobanner": {
            "type": "image",
            "label": "Hero Banner",
            "description": "Hero banner image for homepage"
        },
        "primaryColor": {
            "type": "select",
            "label": "Primary Color",
            "description": "Choose your theme's primary color",
            "options": [
                {"value": "blue", "label": "Blue"},
                {"value": "green", "label": "Green"},
                {"value": "purple", "label": "Purple"},
                {"value": "orange", "label": "Orange"}
            ],
            "default": "blue"
        },
        "showSidebar": {
            "type": "checkbox",
            "label": "Show Sidebar",
            "description": "Display sidebar on all pages",
            "default": true
        },
        "footerText": {
            "type": "text",
            "label": "Footer Text",
            "description": "Custom text to display in footer",
            "default": "© 2024 My Site"
        },
        "socialLinks": {
            "type": "array",
            "label": "Social Links",
            "description": "Add social media links",
            "fields": {
                "name": {"type": "text", "label": "Name"},
                "url": {"type": "text", "label": "URL"},
                "icon": {"type": "text", "label": "Icon Class"}
            }
        }
    }
}

Breadcrumb Options

json
{
    "showBreadcrumbs": {
        "type": "checkbox",
        "label": "Show Breadcrumbs",
        "description": "Display breadcrumb navigation on pages",
        "default": true
    },
    "breadcrumbStyle": {
        "type": "select",
        "label": "Breadcrumb Style",
        "description": "Choose breadcrumb appearance",
        "options": [
            {"value": "minimal", "label": "Minimal (Home > Page)"},
            {"value": "full", "label": "Full Path (Home > Section > Page)"},
            {"value": "custom", "label": "Custom Separator"}
        ],
        "default": "minimal"
    },
    "breadcrumbSeparator": {
        "type": "text",
        "label": "Breadcrumb Separator",
        "description": "Character to separate breadcrumb levels",
        "default": ">"
    }
}

2. Option Types

FearlessCMS supports several option types:

#### Image Upload

json
{
    "logo": {
        "type": "image",
        "label": "Logo",
        "description": "Upload your logo"
    }
}

#### Text Input

json
{
    "siteTitle": {
        "type": "text",
        "label": "Site Title",
        "description": "Your site title",
        "default": "My Site"
    }
}

#### Textarea

json
{
    "footerText": {
        "type": "textarea",
        "label": "Footer Text",
        "description": "Custom text to display in the footer",
        "rows": 3
    }
}

#### Select Dropdown

json
{
    "layout": {
        "type": "select",
        "label": "Layout Style",
        "options": [
            {"value": "wide", "label": "Wide Layout"},
            {"value": "narrow", "label": "Narrow Layout"},
            {"value": "sidebar", "label": "With Sidebar"}
        ],
        "default": "wide"
    }
}

#### Checkbox

json
{
    "showSearch": {
        "type": "checkbox",
        "label": "Show Search",
        "description": "Display search box in header",
        "default": true
    }
}

#### Color Picker

json
{
    "accentColor": {
        "type": "color",
        "label": "Accent Color",
        "description": "Choose accent color",
        "default": "#007bff"
    }
}

#### Array/Repeater

json
{
    "socialLinks": {
        "type": "array",
        "label": "Social Links",
        "fields": {
            "platform": {
                "type": "select",
                "label": "Platform",
                "options": [
                    {"value": "facebook", "label": "Facebook"},
                    {"value": "twitter", "label": "Twitter"},
                    {"value": "instagram", "label": "Instagram"}
                ]
            },
            "url": {
                "type": "text",
                "label": "URL"
            },
            "icon": {
                "type": "text",
                "label": "Icon Class"
            }
        }
    }
}

Using Theme Options in Templates

Basic Usage

Access theme options using the {{themeOptions.key}} syntax:

html
{{#if themeOptions.logo}}
    
{{/if}}

{{#if themeOptions.showSidebar}}

{{/if}}

Using Theme Options with Modular Templates

When using modular templates, theme options work seamlessly across all modules:

Main template (page.html):

html



    {{module=head.html}}




    {{module=header.html}}
    
{{module=hero-banner.html}}
{{module=sidebar.html}}
{{module=footer.html}}

Header module (header.html):

html
{{#if themeOptions.logo}} {{else}}

{{siteName}}

{{/if}} {{#if themeOptions.showSearch}} {{/if}}

Sidebar module (sidebar.html):

html
{{#if themeOptions.showSidebar}}
    
{{/if}}

{{#if themeOptions.showBreadcrumbs}}
    
{{/if}}

Footer module (footer.html):

html
{{#if themeOptions.footerText}}

{{themeOptions.footerText}}

{{else}}

© 2025 {{siteName}}

{{/if}}

This approach allows you to: