40 lines
1.5 KiB
PHP
40 lines
1.5 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Sidebar Partial (v1)
|
|
*
|
|
* This partial dynamically loads a sidebar based on the provided configuration.
|
|
* It allows pages to enable or disable the sidebar and define custom styles.
|
|
*
|
|
* ## Configuration Options:
|
|
* - `enabled` (bool) - Determines whether the sidebar is displayed (default: false)
|
|
* - `width` (string) - Sidebar width percentage (default: '25%')
|
|
* - `position` (string) - Sidebar alignment: 'left' or 'right' (default: 'right')
|
|
* - `widgets` (array) - List of widgets or components to include in the sidebar
|
|
*/
|
|
|
|
// Ensure sidebar visibility is explicitly enabled
|
|
if (!isset($sidebarConfig) || empty($sidebarConfig['enabled'])) {
|
|
return;
|
|
}
|
|
|
|
$sidebarWidth = htmlspecialchars($sidebarConfig['width'] ?? '25%', ENT_QUOTES, 'UTF-8');
|
|
$sidebarPosition = htmlspecialchars($sidebarConfig['position'] ?? 'right', ENT_QUOTES, 'UTF-8');
|
|
$sidebarId = htmlspecialchars($sidebarConfig['id'] ?? 'default', ENT_QUOTES, 'UTF-8');
|
|
$widgets = $sidebarConfig['widgets'] ?? [];
|
|
?>
|
|
|
|
<aside class="sidebar sidebar-<?php echo $sidebarId; ?>" style="width: <?php echo $sidebarWidth; ?>; float: <?php echo $sidebarPosition; ?>;">
|
|
<div class="sidebar-content">
|
|
<?php if (!empty($widgets)) : ?>
|
|
<?php foreach ($widgets as $widget): ?>
|
|
<div class="sidebar-widget">
|
|
<?php echo $widget; ?>
|
|
</div>
|
|
<?php endforeach; ?>
|
|
<?php else: ?>
|
|
<p>No widgets configured.</p>
|
|
<?php endif; ?>
|
|
</div>
|
|
</aside>
|