LogoLogo
  • Introduction
  • Early Access
  • System Requirements
  • Elements FAQ
  • Purchasing & Licensing FAQ
    • License Types
  • Why Elements?
    • Static Website Benefits
    • Build a Digital Garden
  • Community Forum
  • Marketplace
  • Elements App
    • Getting Started
    • Keyboard Shortcuts
    • Migrations
      • Migrating from Blocs
      • Migrating from Classic
      • Migrating from Stacks
    • Design System
    • Editor
      • Apple Intelligence
      • Component Inspector
      • Dark Mode
      • Node Browser
      • Page Manager
      • Preview
      • Resources
      • Responsive Breakpoints
      • Workspaces
    • Components
      • Built-in Components
        • Accordion
        • Background
        • CMS
          • Helpers
          • Available Classes
            • ElementsCMS.php
            • ElementsCMSCollection
            • ElementsCMSItem.php
          • Frontmatter
          • Markdown
          • Online Editor
          • Pretty URLs
          • Syntax
        • Button
        • Container
        • Divider
        • Dropdown
        • Flex
        • Filter
        • Filter Tags
        • Form
        • Gallery
        • Grid
        • Image
        • Menu
        • Modal
        • Modal Close
        • Reveal
        • Image Slider
        • SVG
        • Text
        • Top Pages
        • Typography
        • Video
      • Common Controls
        • Link
        • Layout
        • Sizing
        • Spacing
        • Transitions
        • Effects
        • Filters
        • Transforms
        • Borders
        • Advanced
      • Custom Components
    • Globals
    • Templates
    • Project Settings
      • General
      • Web Icons
      • Advanced
      • Template
      • Publishing
    • Theme Studio
      • Theme
      • Colors
      • Screens
      • Font Family
      • Font Size
      • Spacing
      • Shadows
      • Border Width
      • Border Radius
      • Typography
    • How to
      • Add an Icon Inside a Button
      • Adjust Smooth Scroll Speed
      • Apply Anchor Scroll Padding
      • Add Snow to your Website
      • Build a Sticky Menu
      • Center Align Components
      • Create a Card
      • Site Banner with Text
      • Make a two column layout
    • Resources
    • Troubleshooting
    • SEO
      • Robots.txt
    • Accessibility
    • Advanced
      • URL Scheme
  • Elements Language
    • Introduction
      • Getting Started
      • Component Styling
    • Element Pack
      • info.json
      • Components
        • info.json
        • Icons
        • Properties.json
          • Grouping Controls
          • Default Values
          • General Structure
            • Title
            • ID
            • Format
            • Visible
            • Enabled
            • Responsive
          • UI Controls
            • Divider
            • Heading
            • Image
            • Information
            • Link
            • Number
            • Resource
            • Segmented
            • Select
            • Slider
            • Switch
            • Text
            • Text Area
            • Theme Border Width
            • Theme Border Radius
            • Theme Color
            • Theme Font
            • Theme Spacing
            • Theme Shadow
            • Theme Text Style
            • Theme Typography
        • Templates
          • Portal
          • Backend
          • Conditional Statements
          • Regular Expressions
          • Looping
          • Includes
          • Image Resources
          • HTML
            • Anchor
            • Raw
            • Editable Content
            • Dropzones
            • Inline templates
          • CSS
          • JavaScript
        • Assets
        • Hooks.js
          • Common use cases
          • Passing data to templates
          • Working with Collections
          • Working with UI Controls
          • Working with Resources
          • Available Functions
            • rw.addAnchor
            • rw.getBreakpoints
            • rw.getBreakpointNames
            • rw.getResponsiveValues
            • rw.resizeResource
            • rw.setProps
            • rw.setRootElement
          • Available Data
            • rw.collections
            • rw.component
            • rw.node
            • rw.pages
            • rw.project
            • rw.props
      • Collections
        • Data collections in Hooks.js
        • Accessing Data in Templates
        • Collections in properties.json
      • Shared Files
        • Assets
        • Templates
      • Themes
    • Troubleshooting
  • Elements Cloud
    • Getting Started
    • Troubleshooting
  • Elements Marketplace
    • Getting Started
    • Add-on Guidelines
    • Marketplace API
  • Branding
    • Logotype
    • Logotype Animated
    • Icon
  • Legal
    • Subscription Terms of Service
    • Cloud Terms of Service
    • Frameworks
Powered by GitBook

We are Realmac Software. We make nice things.

On this page
  • Overview
  • Constructor
  • Static Methods
  • Configuration Methods
  • Content Management Methods
  • Usage Examples
  • Dependencies
  • File Structure

Was this helpful?

Edit on GitHub
Export as PDF
  1. Elements App
  2. Components
  3. Built-in Components
  4. CMS
  5. Available Classes

ElementsCMS.php

The ElementsCMS class is a PHP-based content management system that provides functionality for managing CMS collections and items. It serves as the main entry point for interacting with content stored

Overview

The ElementsCMS class manages the base path for content storage and provides methods to create collections, load items, and manage configuration options.

Constructor

__construct(string $basePath, array $options = [])

Creates a new instance of ElementsCMS.Parameters:

  • $basePath (string): The base path for the CMS content storage

  • $options (array, optional): Additional configuration options for the CMS

$cms = new ElementsCMS('/path/to/content', ['debug' => true]);

Static Methods

make(string $basePath, array $options = []): ElementsCMS

Static factory method that creates a new instance of ElementsCMS.Parameters:

  • $basePath (string): The base path for the CMS content storage

  • $options (array, optional): Additional configuration options for the CMS

Returns: ElementsCMS instance

$cms = ElementsCMS::make('/path/to/cms_data');

Configuration Methods

basePath(): string

Returns: The base path as a string

$path = $cms->basePath(); // Returns '/path/to/content'

options(): array

Returns: Array of all options

$allOptions = $cms->options();

option(string $key, $default = null): mixed

Returns: The option value or default value

Parameters:

  • $key (string): The option key to retrieve

  • $default (mixed, optional): Default value returned if the option is not set

$debug = $cms->option('debug', false);
$theme = $cms->option('theme', 'default');

setOption(string $key, $value): void

Sets an option value.

  • $key (string): The option key to set

  • $value (mixed): The value to set

$cms->setOption('debug', true);
$cms->setOption('cache_enabled', false);

Content Management Methods

collection(string $path, array $options = []): ElementsCMSCollection

Creates a new collection instance.Parameters:

  • $path (string): The path for the collection (relative to base path)

  • $options (array, optional): Additional options for the collection

Returns: ElementsCMSCollection instance

$articles = $cms->collection('articles', ['sort' => 'date']);
$projects = $cms->collection('projects');

item(string $collectionPath, string $slug): ?ElementsCMSItem

Loads a specific item from a collection.Parameters:

  • $collectionPath (string): The path of the collection

  • $slug (string): The slug/filename of the item (without .md extension)

Returns: ElementsCMSItem instance or null if not found

$blogPost = $cms->item('blog', 'my-first-post');
$aboutPage = $cms->item('pages', 'about');

Usage Examples

Basic Setup

<?php
require_once '/path/to/ElementsCMS.php';

$cms = ElementsCMS::make(
    '/var/www/cms_data',
    ['debug' => true, 'cache_ttl' => 3600]
);

Working with Collections

// Create a blog collection
$blog = $cms->collection('blog', ['sort' => 'date_desc']);

// Create a pages collection
$pages = $cms->collection('pages');

Loading Individual Items

// Load a specific blog post
$post = $cms->item('blog', 'introduction-to-cms');

// Load a page
$homepage = $cms->item('pages', 'home');

Managing Configuration

// Get configuration
$debugMode = $cms->option('debug', false);
$cacheEnabled = $cms->option('cache_enabled', true);

// Set configuration
$cms->setOption('theme', 'custom');
$cms->setOption('max_items_per_page', 10);

Dependencies

This class requires the following files:

  • ElementsCMSCollection.php

  • ElementsCMSItem.php

Make sure these files are available in the same directory as the ElementsCMS class.

File Structure

The CMS expects content to be organized in the following structure:

  • cms-base-path/

    • collection-name/

      • item-slug.md

      • another-item.md

    • another-collection/

      • item1.md

      • item2.md

Items must be in Markdown files (.md extension) within collection directories.

PreviousAvailable ClassesNextElementsCMSCollection

Last updated 1 day ago

Was this helpful?