Developing for the CMS

The Elements CMS is a powerful content management system designed for RapidWeaver elements, providing a flexible and efficient way to manage content through markdown files with YAML front matter.

Table of Contents

Getting Started

To initialize the CMS in your PHP code:

require_once 'path/to/cms.php';

// Initialize CMS with base path and options
$cms = cms('/path/to/content', [
    'detailPageUrl' => 'https://example.com/posts',
    'prettyUrls' => true
]);

Core Concepts

Collections

Collections are groups of content items stored in markdown files. Each collection is stored in a directory, with each item represented by a markdown file.

Items

Items are individual content pieces stored as markdown files with YAML front matter. The filename format can be either:

  • YYYY-MM-DD-slug.md (for dated content)

  • slug.md (for undated content)

Example item structure:

Working with Collections

Basic Collection Operations

Advanced Filtering

Working with Items

Loading and Accessing Items

Item Relationships

Search Functionality

The CMS includes a powerful search system that can be used in two ways:

AJAX Search Endpoint

The CMS provides a search endpoint at search.php that accepts the following parameters:

  • q: Search query

  • collectionPath: Path to the collection

  • detailPageUrl: URL for detail pages

  • prettyUrls: Whether to use pretty URLs

  • basePath: Base path for content

  • template: HTML template for rendering results, can include Twig syntax

Example AJAX call:

The search system automatically maintains an index file (search-index.json) in the collection directory for improved performance. The index is automatically rebuilt when content changes are detected.

The CMS provides a fluent interface for finding related items:

RSS and Sitemap Generation

RSS Feed

XML Sitemap

Best Practices

  1. File Organization

    • Keep collections in separate directories

    • Use consistent naming conventions for files

    • Include all necessary metadata in front matter

  2. Performance

    • Use caching when appropriate

    • Implement pagination for large collections

    • Optimize search queries

  3. Content Structure

    • Use consistent front matter fields

    • Include required metadata (title, date, status)

    • Properly format markdown content

  4. Security

    • Validate user input

    • Sanitize output

    • Use proper file permissions

Dependencies

The CMS requires the following PHP packages:

  • Symfony YAML

  • CommonMark

  • Illuminate Collections

  • Twig (for template rendering)

Error Handling

The CMS includes built-in error handling for common scenarios:

  • Invalid file paths

  • Missing required metadata

  • Malformed YAML front matter

  • Search index issues

Support

For issues, feature requests, or contributions, please refer to the project's issue tracker or documentation repository.

Last updated

Was this helpful?