How MyStudio themes work: files, sync and the MyBB database

amtekkie · Today

MyStudio's core idea: a theme's files are the truth, and MyBB's database is a cache. You edit files, MyStudio copies them into MyBB (a sync), and MyBB renders the forum as it always has.

In short
  • One template = one .html file; stylesheets are listed in theme.json
  • No PHP in themes: theme PHP lives in inc/plugins/mystudio/themes/{slug}/
  • New files and theme.json changes need a full sync

Files first, database second

  You edit files            Sync                 MyBB reads the database
 ┌──────────────────┐    ┌──────────┐    ┌───────────────────────────────┐
 │ themes/my-theme/ │ ─▶ │ MyStudio │ ─▶ │ templates, stylesheets, theme │ ─▶ your forum
 └──────────────────┘    └──────────┘    └───────────────────────────────┘

If the files and the database ever disagree, the files win: the next sync puts the database right. Because MyBB still reads its own tables, every MyBB feature, hook, template variable and plugin keeps working.

What a theme folder holds

themes/mystudio-default/
├── theme.json          name, version, parent, stylesheets, modules, supports …
├── default.json        saved setting values (written by the Admin CP)
├── screenshot.jpg      1280 × 800, shown on the Themes page
├── css/                stylesheets (listed in theme.json)
├── templates/
│   ├── header/header.html            → MyBB template "header"
│   ├── forumdisplay/forumdisplay_thread.html
│   └── ungrouped/headerinclude.html
├── js/                 scripts, loaded from here by templates
├── images/             theme images, logos
└── vendor/             third-party files (Bootstrap, Bootstrap Icons)
  1. One template = one .html file, named after the MyBB template. header.html is header.
  2. Sub-folders are only for tidiness. MyBB doesn't care which folder a template is in.
  3. Stylesheets must be listed in theme.json, with where they load (every page, or chosen scripts). See the theme.json reference.

Where PHP lives (never in the theme)

Themes contain no PHP. Anything in themes/ could arrive in an uploaded ZIP, and an uploaded theme must never run code. When a theme needs PHP, it lives in fixed places outside the theme:

WhatWhere
Theme hooks (PHP that runs on every page)inc/plugins/mystudio/themes/{slug}/hooks.php
Page shell and sidebar helpersinc/plugins/mystudio/themes/{slug}/layout.php
Settings schemainc/plugins/mystudio/themes/{slug}/options.php
Language stringsinc/plugins/mystudio/themes/{slug}/lang/{language}/*.lang.php
Features for every themeModules: inc/plugins/mystudio/modules/{id}/

The .htaccess files in themes/ and inc/plugins/mystudio/ only let assets (CSS, JS, images, fonts) through to browsers.

When to sync

You changed…What to do
An existing template or stylesheet in the Admin CP editorNothing: Ctrl+S updates MyBB at once.
An existing file in your own editor or by FTPSync (Themes page, the editor's sync button, or cli.php sync).
Added a new template or stylesheetA full sync: quick saves only update files MyBB already knows.
theme.jsonA full sync.
Theme PHP (hooks, language files)Nothing: PHP is read on every page.

During development, turn on auto-sync in Dev Options: save in your editor and the forum syncs and reloads by itself.

What a sync does

  • Reads the theme (and, for a child theme, its whole parent chain), builds the complete theme and imports it with MyBB's own theme importer. Changed templates get an incremental update.
  • Checks every template with MyBB's template security check and refuses anything that could run PHP.
  • Writes the compiled CSS to cache/themes/; JS stays in the theme's js/ folder.
  • Re-syncs the theme's child themes.

It also works the other way: a theme that only exists in the database can be extracted to files with Convert to Disk.

Settings live outside the theme files

SettingsStored in
Theme settings (colour, logo …)The theme's default.json; schema in options.php
MyStudio Options (layout, header, sidebar …)The database, per theme
Module settingsThe database, shared by all themes

So updates can replace a shipped theme's files without losing anyone's settings.

Why files make theme building easier

FindableYour editor's search finds the template and CSS for any part of the page.
DiffsEvery change can be reviewed and reverted in version control.
Small mistakesRestyling can't break server code.
Instant feedbackWith auto-sync.
Predictable namesKnow MyBB, know where postbit_classic lives.

Next: create your own theme.