v2.6.3 (Lyra): Content multi-type handling, getAllPages() structuur, . verberg-prefix
- Content bestanden met dezelfde naam maar ander type (md/php/html) worden correct geserveerd: URL met extensie opent dat bestand, URL zonder extensie valt terug op md > php > html (resolveContentByType helper) - Admin content editor accepteert bestanden met dezelfde naam (ander type); preview-knop linkt per extensie - Frontend navigatie/directory listing/search tonen elk bestandstype apart - getAllPages() array structuur gewijzigd naar list van ['path','title','type'] met type 'md'/'php'/'html'/'folder' - Verberg-prefix logica: _ is geen verberg-prefix meer, alleen . (en -); admin toont wél alle . bestanden/mappen - ContentAPI getPage()/pageExists() respecteren expliciete extensie - Handleiding content-api.md (NL+EN) herschreven - File-tree unificatie: _file-tree.twig + _editor-styles.twig includes - Versie verhoogd naar 2.6.3
This commit is contained in:
@@ -1,13 +1,8 @@
|
||||
# Content management
|
||||
|
||||
CodePress offers two views for content management:
|
||||
CodePress uses a **tree view** (`/admin/content`) for content management: a file browser sidebar + CodeMirror editor, uniform with the plugin and theme editors. The old list/table view has been removed.
|
||||
|
||||
1. **Tree view** (`/admin/content`) — default, file browser sidebar + CodeMirror editor (uniform with plugin/theme editors)
|
||||
2. **List view** (`/admin/content-list`) — classic table with filter, upload, new folder/file per folder
|
||||
|
||||
Both work side-by-side and use the same content directory. Switch between views via the "List view"/"Tree view" buttons at the top right. The tree view offers the same functionality as the list view, but with a nested file-tree sidebar like the plugin and theme editors — for a consistent editor experience.
|
||||
|
||||
## Tree view (content)
|
||||
## Content editor
|
||||
|
||||
### File browser sidebar
|
||||
- Shows the nested file tree of `content/`
|
||||
@@ -19,6 +14,30 @@ Both work side-by-side and use the same content directory. Switch between views
|
||||
### Editable file types
|
||||
`.md` (Markdown), `.php` (PHP), `.html` (HTML) — consistent with the existing content-edit page.
|
||||
|
||||
All types support `---` frontmatter (layout, created, edited, plugins). The CMS `parseMetadata()` extracts frontmatter before processing. For PHP files, frontmatter is stripped from the output.
|
||||
|
||||
#### PHP content files
|
||||
PHP files can deliver content in two ways:
|
||||
1. **Echo** (output buffering): everything `echo`ed or outside `<?php` tags is used as content
|
||||
2. **Return** (callback style): `return '<h1>Hello</h1>';` — the returned string is used as content
|
||||
|
||||
In PHP files, the `ContentAPI` is available via `$api`:
|
||||
```php
|
||||
<?php
|
||||
$menu = $api->getMenu();
|
||||
$pages = $api->getAllPages();
|
||||
$config = $api->getConfig('site_title');
|
||||
return '<h1>' . htmlspecialchars($config) . '</h1>';
|
||||
```
|
||||
|
||||
#### Frontend URLs and file names
|
||||
The CMS searches files in order: `.md` → `.php` → `.html`. If files share the same name (e.g. `test.md` and `test.php`), `/nl/test` always opens `test.md`. To open a specific file type, add the extension to the URL:
|
||||
- `/nl/test` → opens `test.md` (or `.php` / `.html` if `.md` doesn't exist)
|
||||
- `/nl/test.php` → opens `test.php` (explicit extension)
|
||||
- `/nl/test.html` → opens `test.html` (explicit extension)
|
||||
|
||||
The preview link in the editor automatically uses the extension for non-`.md` files.
|
||||
|
||||
### Set image size (Markdown)
|
||||
The markdown editor toolbar has an "Image size" button (expand icon):
|
||||
1. Select an image in the editor in markdown format ``
|
||||
@@ -41,7 +60,7 @@ Images in `content/` are served via the `/-media/` endpoint (content/ lives outs
|
||||
- Enter a path within content (e.g. `en.page` or `blog/en.post`)
|
||||
- Choose the file type (Markdown/PHP/HTML)
|
||||
- Subfolders are created automatically
|
||||
- Frontmatter with `layout`, `author_name`, `author_email`, `created` is auto-generated
|
||||
- Frontmatter with `layout`, `created`, `edited` is auto-generated
|
||||
|
||||
### Upload a file
|
||||
- Click **Upload** to upload files to `content/`
|
||||
@@ -62,27 +81,22 @@ Images in `content/` are served via the `/-media/` endpoint (content/ lives outs
|
||||
On the editor page you can choose the layout from the layouts defined in `theme.json` (template mapping). The selected layout is stored in the frontmatter `layout:` key.
|
||||
|
||||
### Plugins on pages
|
||||
- Content plugins (from `plugin.json` with `type: "content"`) appear in the plugin selection
|
||||
- Choose which plugins run on the page
|
||||
- Only active **content plugins** (from `plugin.json` with `type: "content"`) appear in the plugin multiselect; system plugins (like Statistics/Logs/Dashboard) are excluded
|
||||
- Choose which plugins run on the page via the multiselect (use Ctrl/Cmd+click for multiple)
|
||||
- The plugin selection is stored in the frontmatter `plugins:` key
|
||||
|
||||
### Git / Backup integration (Phase 5)
|
||||
At the top of the content editor there are backup and git actions:
|
||||
- **Git init**: initializes a git repository in `content/` (if none exists yet)
|
||||
- **Commit**: commits all uncommitted changes (only if there is a git repo and there are changes)
|
||||
- **Backup**: link to the backup page (`/admin/content-backup`) for ZIP backup/restore
|
||||
- The git status badge shows the current branch, whether there are uncommitted changes, and the last commit
|
||||
### Backup integration
|
||||
At the top of the content editor there is a **Backup** button linking to the backup page (`/admin/content-backup`) for ZIP backup/restore and (if available) git versioning. Git integration in the editor sidebar has been removed; git will become a system plugin later.
|
||||
|
||||
### Frontmatter
|
||||
|
||||
The editor updates the frontmatter live when layout or plugin selection changes:
|
||||
The editor shows the **Created** and **Edited** timestamps (read-only, automatically updated on every save). The `edited:` value is refreshed on each save.
|
||||
|
||||
```markdown
|
||||
---
|
||||
layout: left_sidebar
|
||||
author_name: Admin
|
||||
author_email: admin@example.com
|
||||
created: 2026-08-19 10:30:25
|
||||
edited: 2026-08-20 14:22:01
|
||||
plugins: HTMLBlock, Navigation
|
||||
---
|
||||
|
||||
@@ -91,24 +105,6 @@ plugins: HTMLBlock, Navigation
|
||||
Content...
|
||||
```
|
||||
|
||||
## List view (content)
|
||||
|
||||
### Managing files
|
||||
|
||||
- **New folder** — Create folder structure
|
||||
- **New file** — Create a page (`.md`, `.php`, `.html`)
|
||||
- **Edit** — Modify existing content in the CodeMirror editor
|
||||
- **Rename** — Change file or folder names
|
||||
- **Move** — Move content to another folder
|
||||
- **Delete** — Remove content
|
||||
- **Rename folder** — Change a folder name
|
||||
|
||||
### Editor (content-edit)
|
||||
|
||||
- **CodeMirror** with syntax highlighting (Markdown, PHP, HTML)
|
||||
- **Toolbar** for quickly inserting Markdown
|
||||
- **Shortcuts**: Ctrl+S (save), Ctrl+N (new)
|
||||
|
||||
## Frontmatter
|
||||
|
||||
The editor updates the frontmatter live when layout or plugin selection changes:
|
||||
@@ -116,9 +112,9 @@ The editor updates the frontmatter live when layout or plugin selection changes:
|
||||
```markdown
|
||||
---
|
||||
layout: left_sidebar
|
||||
plugins:
|
||||
- HTMLBlock
|
||||
- Navigation
|
||||
created: 2026-08-19 10:30:25
|
||||
edited: 2026-08-20 14:22:01
|
||||
plugins: HTMLBlock, Navigation
|
||||
---
|
||||
|
||||
# Page title
|
||||
|
||||
@@ -1,84 +1,132 @@
|
||||
# Content API
|
||||
|
||||
The Content API is available in PHP content files (`.php`) and provides a safe, read-only interface to CMS data.
|
||||
PHP content files (`.php`) run inside the CMS and have access to a safe,
|
||||
read-only API via the `$api` variable. The output of such a file is
|
||||
automatically placed into the active Twig layout at the `{{ content }}` spot.
|
||||
|
||||
## Usage in PHP content files
|
||||
## How to pass content to the Twig template
|
||||
|
||||
There are **two ways** to send content from a `.php` file to the Twig template.
|
||||
The CMS picks the right one automatically:
|
||||
|
||||
1. **Echo / print** — everything you echo (or that sits outside `<?php ?>` tags)
|
||||
is captured and placed as `{{ content }}` in the layout.
|
||||
2. **Return** — if you `return` a string, that string is used as `{{ content }}`
|
||||
(any echoed output is then ignored).
|
||||
|
||||
Example with echo:
|
||||
|
||||
```php
|
||||
---
|
||||
layout: full_content
|
||||
---
|
||||
<?php
|
||||
/** @var ContentAPI $api */
|
||||
|
||||
// Get all pages
|
||||
$allPages = $api->getAllPages();
|
||||
// Result: ['index' => 'Home', 'about-us' => 'About Us', ...]
|
||||
|
||||
// Get a specific page
|
||||
$page = $api->getPage('about-us');
|
||||
// Result: ['title' => 'About Us', 'content' => '...', 'path' => 'about-us', 'layout' => 'full_content', 'metadata' => [...]]
|
||||
|
||||
// Get menu structure
|
||||
$menu = $api->getMenu();
|
||||
// Result: [['title' => 'Home', 'path' => 'index', 'type' => 'file', 'active' => true], ...]
|
||||
|
||||
// Get config value (dot notation)
|
||||
$siteTitle = $api->getConfig('site_title');
|
||||
$searchEnabled = $api->getConfig('features.search_enabled', false);
|
||||
?>
|
||||
<h1>Hello <?= htmlspecialchars($api->getSiteTitle()) ?></h1>
|
||||
<p>Welcome to my page.</p>
|
||||
```
|
||||
|
||||
## Available methods
|
||||
Example with return:
|
||||
|
||||
```php
|
||||
---
|
||||
layout: full_content
|
||||
---
|
||||
<?php
|
||||
/** @var ContentAPI $api */
|
||||
return '<h1>Hello ' . htmlspecialchars($api->getSiteTitle()) . '</h1>';
|
||||
```
|
||||
|
||||
> The frontmatter (`---` block) is stripped by the CMS before the PHP code
|
||||
> runs. The layout key determines which Twig template surrounds the content.
|
||||
|
||||
## What you cannot do
|
||||
|
||||
- You **cannot** set your own Twig variables from a `.php` file. PHP content
|
||||
only feeds the `{{ content }}` placeholder. Other template variables
|
||||
(`menu`, `breadcrumb`, `page_title`, etc.) are set by the CMS based on
|
||||
frontmatter and config — not by your PHP code.
|
||||
- You **cannot** call a ContentAPI from the outside; the class is only
|
||||
instantiated inside `parsePHP()` and is never reachable via a URL.
|
||||
|
||||
## Available variables in your PHP file
|
||||
|
||||
The following variables are available inside a `.php` content file:
|
||||
|
||||
| Variable | Type | Description |
|
||||
|----------|------|-------------|
|
||||
| `$api` | `ContentAPI` | Read-only access to CMS data |
|
||||
| `$pageMetadata` | `array` | The frontmatter metadata of this file |
|
||||
|
||||
## ContentAPI methods
|
||||
|
||||
### Pages
|
||||
|
||||
- `getAllPages(): array` - All pages as `['path' => 'title']` pairs
|
||||
- `getPage(string $path): ?array` - Specific page with `title`, `content`, `path`, `layout`, `metadata`
|
||||
- `pageExists(string $path): bool` - Check if a page exists
|
||||
- `getCurrentPageTitle(): string` - Title of current page
|
||||
- `getCurrentPagePath(): string` - Path of current page
|
||||
- `isHomepage(): bool` - Whether current page is the homepage
|
||||
- `getAllPages(): array` — All content entries (folders + files) as a list of `['path' => ..., 'title' => ..., 'type' => ...]`. `type` is `md`/`php`/`html` for files, `folder` for directories.
|
||||
- `getPage(string $path): ?array` — A specific page; returns `title`, `content`, `path`, `layout`, `metadata`. `$path` may include an extension.
|
||||
- `pageExists(string $path): bool` — Check whether a page exists
|
||||
- `getCurrentPageTitle(): string` — Title of the current page
|
||||
- `getCurrentPagePath(): string` — Path of the current page
|
||||
- `isHomepage(): bool` — Whether the current page is the homepage
|
||||
|
||||
### Menu & Navigation
|
||||
### Menu & navigation
|
||||
|
||||
- `getMenu(): array` - Hierarchical menu structure with `title`, `path`, `children`, `active`
|
||||
- `buildUrl(string $page = 'index', ?string $lang = null, array $params = []): string` - Build a URL for a page
|
||||
- `getMenu(): array` — Hierarchical menu structure with `title`, `path`, `children`, `active`
|
||||
- `buildUrl(string $page = 'index', ?string $lang = null, array $params = []): string` — Build a URL
|
||||
|
||||
### Configuration
|
||||
|
||||
- `getConfig(string $key, mixed $default = null): mixed` - Config value via dot notation (e.g. `'features.search_enabled'`)
|
||||
- `getSiteTitle(): string` - Site title from config
|
||||
- `getConfig(string $key, mixed $default = null): mixed` — Config value via dot notation (e.g. `'features.search_enabled'`)
|
||||
- `getSiteTitle(): string` — Site title from config
|
||||
|
||||
### Language
|
||||
|
||||
- `getCurrentLanguage(): string` - Current language code (e.g. `'nl'`)
|
||||
- `getAvailableLanguages(): array` - Available languages (e.g. `['nl', 'en']`)
|
||||
- `t(string $key): string` - Translate a language key
|
||||
- `getCurrentLanguage(): string` — Current language code (e.g. `'nl'`)
|
||||
- `getAvailableLanguages(): array` — Available languages
|
||||
- `t(string $key): string` — Translate a language key
|
||||
|
||||
### Search
|
||||
|
||||
- `getSearchResults(): array` - Search results (empty if not searching)
|
||||
- `isSearching(): bool` - Whether a search is currently active
|
||||
- `getSearchResults(): array` — Search results (empty if not searching)
|
||||
- `isSearching(): bool` — Whether a search is currently active
|
||||
|
||||
## Example: Show recent pages
|
||||
### Author
|
||||
|
||||
- `getPageAuthor(): array` — Author metadata from frontmatter (`author_name`, `author_email`, `created`)
|
||||
|
||||
## Examples
|
||||
|
||||
### Show recent pages
|
||||
|
||||
```php
|
||||
---
|
||||
layout: full_content
|
||||
---
|
||||
<?php
|
||||
/** @var ContentAPI $api */
|
||||
$pages = $api->getAllPages();
|
||||
$entries = $api->getAllPages();
|
||||
$currentLang = $api->getCurrentLanguage();
|
||||
?>
|
||||
<ul>
|
||||
<?php foreach (array_slice($pages, 0, 5, true) as $path => $title): ?>
|
||||
<?php foreach ($entries as $entry): ?>
|
||||
<?php if ($entry['type'] === 'folder') continue; // skip folders ?>
|
||||
<li>
|
||||
<a href="/<?= $currentLang ?>/<?= htmlspecialchars($path) ?>">
|
||||
<?= htmlspecialchars($title) ?>
|
||||
<a href="/<?= htmlspecialchars($currentLang) ?>/<?= htmlspecialchars($entry['path']) ?>">
|
||||
<?= htmlspecialchars($entry['title']) ?>
|
||||
<small>(<?= htmlspecialchars($entry['type']) ?>)</small>
|
||||
</a>
|
||||
</li>
|
||||
<?php endforeach; ?>
|
||||
</ul>
|
||||
```
|
||||
|
||||
## Example: Using config values
|
||||
### Use a config value
|
||||
|
||||
```php
|
||||
---
|
||||
layout: full_content
|
||||
---
|
||||
<?php
|
||||
/** @var ContentAPI $api */
|
||||
if ($api->getConfig('features.search_enabled', false)): ?>
|
||||
@@ -89,6 +137,44 @@ if ($api->getConfig('features.search_enabled', false)): ?>
|
||||
<?php endif; ?>
|
||||
```
|
||||
|
||||
### Dynamic greeting based on language
|
||||
|
||||
```php
|
||||
---
|
||||
layout: full_content
|
||||
---
|
||||
<?php
|
||||
/** @var ContentAPI $api */
|
||||
$lang = $api->getCurrentLanguage();
|
||||
$greeting = $lang === 'nl' ? 'Welkom' : 'Welcome';
|
||||
?>
|
||||
<h1><?= $greeting ?> to <?= htmlspecialchars($api->getSiteTitle()) ?></h1>
|
||||
```
|
||||
|
||||
## Choosing a layout
|
||||
|
||||
The frontmatter `layout` key determines which Twig template surrounds your
|
||||
content. Available layouts are defined in `themes/<active-theme>/theme.json`
|
||||
under the `template` section. For example:
|
||||
|
||||
```yaml
|
||||
---
|
||||
layout: sidebar-content
|
||||
---
|
||||
```
|
||||
|
||||
If you omit a layout, `config.default_template` is used, falling back to
|
||||
`full_content`. The content always lands at the `{{ content }}` spot in that
|
||||
template.
|
||||
|
||||
## Security
|
||||
|
||||
- Always use `htmlspecialchars()` for output of user-content or API data.
|
||||
- PHP content files have access to the server filesystem — be careful with
|
||||
`include`, `require` or `file_get_contents` on external paths. Stay inside
|
||||
the `content/` directory.
|
||||
- The ContentAPI is read-only; you cannot modify files or config through it.
|
||||
|
||||
## CMSAPI (for plugins)
|
||||
|
||||
Plugins use the `CMSAPI` class via `$this->api`. It offers similar methods:
|
||||
@@ -108,12 +194,12 @@ $this->api->createUrl('about-us');
|
||||
$this->api->translate('home');
|
||||
```
|
||||
|
||||
Additionally, CMSAPI provides:
|
||||
In addition, CMSAPI has:
|
||||
|
||||
- `getCurrentPage(): array` - Full page data
|
||||
- `getCurrentPageUrl(): string` - URL of current page
|
||||
- `getCurrentPageFileInfo(): ?array` - File info (created, modified)
|
||||
- `getBreadcrumb(): string` - Breadcrumb HTML
|
||||
- `executePhpFile(string $filePath): string` - Execute PHP file and capture output
|
||||
- `getFileContent(string $filePath): string` - Get content from PHP/HTML/Markdown file
|
||||
- `contentFileExists(string $filename): bool` - Check if file exists in content directory
|
||||
- `getCurrentPage(): array` — Full page data
|
||||
- `getCurrentPageUrl(): string` — URL of the current page
|
||||
- `getCurrentPageFileInfo(): ?array` — File info (created, modified)
|
||||
- `getBreadcrumb(): string` — Breadcrumb HTML
|
||||
- `executePhpFile(string $filePath): string` — Execute a PHP file and capture output
|
||||
- `getFileContent(string $filePath): string` — Get content from a PHP/HTML/Markdown file
|
||||
- `contentFileExists(string $filename): bool` — Check whether a file exists in the content directory
|
||||
Reference in New Issue
Block a user