Add a complete documentation site for Plugi with the following pages: - Readme.md: project overview, quick start, and key features - GettingStarted.md: installation guide, requirements, and first steps - Configuration.md: full reference for .env and config.php settings - Themes.md: theme structure, blocks, layouts, and asset compilation - Extensions.md: extension architecture, routes, blocks, and admin pages Also add index.html (Docsify entry point), _sidebar.md (navigation), favicon.ico, and .nojekyll to prevent GitHub Pages from interfering.
335 lines
9.9 KiB
Markdown
335 lines
9.9 KiB
Markdown
# 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
|
|
<?php
|
|
|
|
return [
|
|
'title' => '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
|
|
<?php
|
|
return [
|
|
'title' => '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
|
|
<div class="paragraph">
|
|
<p>{{ content }}</p>
|
|
</div>
|
|
```
|
|
|
|
**PHP blocks** (`view.php`) have full PHP access. The `$block` variable provides:
|
|
|
|
```php
|
|
<section class="quote-block">
|
|
<blockquote>
|
|
<p>"<?= $block->setting('quote_text') ?>"</p>
|
|
</blockquote>
|
|
<cite>— <?= $block->setting('person') ?></cite>
|
|
</section>
|
|
```
|
|
|
|
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
|
|
<?php
|
|
namespace ThemeOne\Blocks\Quote;
|
|
|
|
use Plugi\Modules\GrapesJS\Block\BaseController;
|
|
|
|
class Controller extends BaseController
|
|
{
|
|
public function index()
|
|
{
|
|
// Custom logic before rendering the view
|
|
$this->view['extra_data'] = 'hello';
|
|
}
|
|
}
|
|
```
|
|
|
|
**model.php:**
|
|
```php
|
|
<?php
|
|
namespace ThemeOne\Blocks\Quote;
|
|
|
|
use Plugi\Modules\GrapesJS\Block\BaseModel;
|
|
|
|
class Model extends BaseModel
|
|
{
|
|
// Custom data handling
|
|
}
|
|
```
|
|
|
|
The namespace is auto-generated from the theme and block folder names, or you can set it explicitly in `config.php`:
|
|
|
|
```php
|
|
'namespace' => '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
|
|
<!doctype html>
|
|
<html lang="<?= phpb_current_language() ?>">
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<title><?= phpb_e($page->getTranslation('meta_title')) ?></title>
|
|
<link href="<?= phpb_theme_asset('dist/style.css') ?>" rel="stylesheet">
|
|
<?= \Plugi\Extensions::getHeaderAssets() ?>
|
|
</head>
|
|
<body>
|
|
<header>
|
|
<!-- Navigation -->
|
|
</header>
|
|
|
|
<main>
|
|
<?= $body ?>
|
|
</main>
|
|
|
|
<footer>
|
|
<!-- Footer content -->
|
|
</footer>
|
|
|
|
<script src="<?= phpb_theme_asset('dist/script.js') ?>"></script>
|
|
<?= \Plugi\Extensions::getFooterAssets() ?>
|
|
</body>
|
|
</html>
|
|
```
|
|
|
|
### 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
|
|
<?php
|
|
// translations/en.php
|
|
return [
|
|
'theme' => [
|
|
'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
|
|
<link href="<?= phpb_theme_asset('dist/style.css') ?>" rel="stylesheet">
|
|
<script src="<?= phpb_theme_asset('dist/script.js') ?>"></script>
|
|
```
|
|
|
|
## 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
|
|
<?php
|
|
return [
|
|
'title' => '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.
|