- Reorganize admin into admin/theme/default/ (views + assets) - Rename GuideNav to Navigation plugin (essential, protected) - Plugin assets support (SCSS/CSS) loaded after theme CSS - User roles: Admin, Content Manager, BI Manager, Site Admin - Role-based access control (RBAC) for admin routes and sidebar - Guide restructure: sub-topics in separate folders with sidebar nav - Dynamic breadcrumb for homepage and subdirectories - Fix theme path traversal (../../ -> ../) in admin.php - Fix CodeMirror mode load order (xml -> css -> js -> htmlmixed -> php) - Fix editor-toolbar.js null checks for plugin edit pages - Layout select from theme.json with live frontmatter update - Footer sticky at bottom of viewport (min-height: 100vh) - Breadcrumb color fix (var(--nav-font) -> var(--header-bg)) - Remove language switcher from guide pages - Update README.md and README.en.md - Bump version to 2.5.1
3.7 KiB
3.7 KiB
Content API
The Content API is available in PHP content files (.php) and provides a safe, read-only interface to CMS data.
Usage in PHP content files
<?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);
Available methods
Pages
getAllPages(): array- All pages as['path' => 'title']pairsgetPage(string $path): ?array- Specific page withtitle,content,path,layout,metadatapageExists(string $path): bool- Check if a page existsgetCurrentPageTitle(): string- Title of current pagegetCurrentPagePath(): string- Path of current pageisHomepage(): bool- Whether current page is the homepage
Menu & Navigation
getMenu(): array- Hierarchical menu structure withtitle,path,children,activebuildUrl(string $page = 'index', ?string $lang = null, array $params = []): string- Build a URL for a page
Configuration
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
Search
getSearchResults(): array- Search results (empty if not searching)isSearching(): bool- Whether a search is currently active
Example: Show recent pages
<?php
/** @var ContentAPI $api */
$pages = $api->getAllPages();
$currentLang = $api->getCurrentLanguage();
?>
<ul>
<?php foreach (array_slice($pages, 0, 5, true) as $path => $title): ?>
<li>
<a href="/<?= $currentLang ?>/<?= htmlspecialchars($path) ?>">
<?= htmlspecialchars($title) ?>
</a>
</li>
<?php endforeach; ?>
</ul>
Example: Using config values
<?php
/** @var ContentAPI $api */
if ($api->getConfig('features.search_enabled', false)): ?>
<form method="GET" action="">
<input type="search" name="search" placeholder="<?= $api->t('search_placeholder') ?>">
<button type="submit"><?= $api->t('search_button') ?></button>
</form>
<?php endif; ?>
CMSAPI (for plugins)
Plugins use the CMSAPI class via $this->api. It offers similar methods:
$this->api->getCurrentPageTitle();
$this->api->getCurrentPageContent();
$this->api->getMenu();
$this->api->getConfig('site_title');
$this->api->getCurrentLanguage();
$this->api->isHomepage();
$this->api->hasContent();
$this->api->getSearchResults();
$this->api->isSearching();
$this->api->getAvailableLanguages();
$this->api->createUrl('about-us');
$this->api->translate('home');
Additionally, CMSAPI provides:
getCurrentPage(): array- Full page datagetCurrentPageUrl(): string- URL of current pagegetCurrentPageFileInfo(): ?array- File info (created, modified)getBreadcrumb(): string- Breadcrumb HTMLexecutePhpFile(string $filePath): string- Execute PHP file and capture outputgetFileContent(string $filePath): string- Get content from PHP/HTML/Markdown filecontentFileExists(string $filename): bool- Check if file exists in content directory