# Themes Themes define the visual appearance and building blocks of your Plugi website. Each theme contains **blocks** (reusable page components), **layouts** (page templates), static pages, and compiled assets. ## Theme Structure A theme lives in the `themes/` directory as a subfolder. The folder name is the theme's slug: ``` themes/ └── theme-one/ ├── config.php # Theme metadata and settings ├── preview.jpg # Theme preview image (shown in admin) ├── blocks/ # Reusable page components │ ├── paragraph/ │ │ ├── config.php │ │ └── view.html │ ├── quote/ │ │ ├── config.php │ │ └── view.php │ └── ... ├── layouts/ # Page layout templates │ └── master/ │ ├── config.php │ └── view.php ├── pages/ # Static pages (e.g., 404.php) ├── translations/ # Theme-specific translations │ ├── en.php │ └── de.php ├── dist/ # Compiled CSS and JS │ ├── style.css │ └── script.js ├── src/ # Source files (Sass, TypeScript, etc.) └── package.json # Node.js dependencies for building assets ``` ## Theme Configuration The `config.php` file defines theme metadata and optional settings: ```php 'Theme One', 'author' => 'Your Name', 'licence' => 'MIT', 'version' => '1.0.0', 'settings' => [ [ 'name' => 'primaryColor', 'label' => 'Primary Color', 'default' => '#3b82f6', 'type' => 'text', ], ], ]; ``` | Key | Description | |-------------|---------------------------------------------------------------| | `title` | Display name of the theme. | | `author` | Theme author name. | | `licence` | License identifier. | | `version` | Semantic version string. | | `settings` | Array of setting definitions available in the admin panel. | ## Blocks Blocks are the building blocks of your pages. Each block is a subfolder inside `blocks/` and contains at minimum a `config.php` and a view file. ### Block Folders Blocks can be organized into subfolders: | Subfolder | Purpose | |-----------------|------------------------------------------------------------| | (root) | Default blocks, always available. | | `archived/` | Deprecated or archived blocks. | | `elements/` | Reusable UI elements. | | `php/` | Blocks that require PHP execution. | ### Block Files A block directory can contain the following files: | File | Required | Description | |-------------------------|----------|------------------------------------------------------------| | `config.php` | Yes | Block configuration (title, icon, settings, category). | | `view.html` | One of | HTML template for the block. | | `view.php` | these | PHP template for the block (enables PHP execution). | | `controller.php` | No | Custom controller class for the block. | | `model.php` | No | Custom model class for the block. | | `script.js` | No | JavaScript executed on the public page. | | `builder-script.js` | No | JavaScript executed in the page builder preview. | ### Block Configuration ```php 'Quote', 'category' => 'General', 'icon' => 'fa fa-quote-left', 'hidden' => false, // Hide from block library if true 'cache' => true, // Allow caching (default: true) 'cache_lifetime' => 3600, // Cache TTL in seconds 'wrapper' => 'div', // Wrapper element for PHP blocks 'whitelist' => [], // Domain whitelist (empty = all domains) 'settings' => [ 'person' => [ 'label' => 'Person Name', 'type' => 'text', 'placeholder' => 'John Doe', 'value' => 'Michael Gough', ], ], ]; ``` ### Block Views **HTML blocks** (`view.html`) are rendered as-is. Use `{{ setting_name }}` syntax for settings: ```html

{{ content }}

``` **PHP blocks** (`view.php`) have full PHP access. The `$block` variable provides: ```php

"setting('quote_text') ?>"

— setting('person') ?>
``` Available methods on `$block`: - `$block->setting('key')` — Get a setting value. - `$block->get('config_key')` — Get a value from `config.php`. - `$block->get('config.nested.key')` — Dot notation for nested config. ### Block Controllers and Models For complex blocks, you can add a controller and/or model: **controller.php:** ```php view['extra_data'] = 'hello'; } } ``` **model.php:** ```php 'MyCustom\Namespace', ``` ## Layouts Layouts define the overall page structure (header, navigation, footer). Each layout is a subfolder inside `layouts/`. ### Layout Files | File | Required | Description | |----------------|----------|------------------------------------------------------------| | `config.php` | No | Layout configuration. | | `view.php` | Yes | PHP template for the layout. | ### Layout View The layout view receives two variables: - `$body` — The rendered page content (blocks). - `$page` — The current page object. Example `view.php`: ```php <?= phpb_e($page->getTranslation('meta_title')) ?>
``` ### Available Variables in Layouts | Variable | Description | |-------------|------------------------------------------------| | `$body` | Rendered page content (all blocks combined). | | `$page` | Current `Page` object with translation methods.| ### Page Methods - `$page->getTranslation('field')` — Get a translated field value. - `$page->get('field')` — Get a page field value. - `$page->get('type')` — Get page type (e.g., `redirect`). ## Static Pages Place static PHP pages in the `pages/` directory. Plugi looks for special pages here: - `404.php` — Custom 404 error page. ## Translations Theme translations go in the `translations/` directory: ```php [ 'welcome' => 'Welcome to our site', 'footer' => 'All rights reserved', ], ]; ``` Translations are merged with core translations and can be overridden per language. ## Assets Themes typically use a build pipeline (Webpack, Vite, etc.) to compile source files into the `dist/` directory: ``` theme-one/ ├── src/ │ ├── styles/ │ │ └── main.scss │ └── scripts/ │ └── main.ts ├── dist/ │ ├── style.css # Compiled CSS │ └── script.js # Compiled JS └── package.json # Build dependencies ``` Reference compiled assets in your views: ```php ``` ## Creating a New Theme 1. **Create a folder** inside `themes/` with your theme's slug: ```bash mkdir themes/my-theme ``` 2. **Add `config.php`**: ```php 'My Theme', 'author' => 'Your Name', 'licence' => 'MIT', 'version' => '1.0.0', ]; ``` 3. **Create a layout** in `layouts/master/view.php` with your HTML structure. 4. **Add blocks** in `blocks/` with `config.php` and view files. 5. **Set as active** in `config.php`: ```php 'theme' => [ 'active_theme' => 'my-theme', ], ``` 6. **Add a preview image** (`preview.jpg`) so the theme appears in the admin panel's theme selector. ## Switching Themes You can switch themes from the admin panel (Settings → Theme) or by changing `theme.active_theme` in `config.php`. The value must match a folder name inside `themes/`. ## Extension Blocks and Layouts Extensions can also provide blocks and layouts that are merged with the active theme's blocks and layouts. See the [Extensions](Extensions.md) documentation for details.