Content Repository
The Content Repository abstracts the details of loading and querying content files. It provides a clean interface for finding individual pages and listing all content in a section.
The repository hides complexity. Your code just asks for content — it doesn't care where it lives.
What Is a Repository?
A repository is a design pattern that acts as a middleman between your code and data storage. In Wordless, the repository hides the complexity of:
- Locating files in the filesystem
- Parsing PHP content files
- Extracting metadata
- Building structured
Contentobjects
Core Methods
find()
Retrieve a single page by its path:
$repo = $container->get(ContentRepositoryInterface::class);
$page = $repo->find('/blog/hello-world');
if ($page) {
echo $page->title;
echo $page->body;
echo $page->get('author');
}
all()
List all content in a section:
// All content
$pages = $repo->all();
// Only blog posts
$posts = $repo->all('blog');
Metadata Inheritance
Child pages automatically inherit metadata from their parent index.php.
Innermost metadata wins on conflict.
| File | Metadata | Result |
|---|---|---|
es/index.php |
language: es |
Inherited by children |
es/algo.php |
title: Algo |
Merged with parent |
Content Objects
The repository returns Content value objects:
$content->title- The page title extracted from metadata
$content->body- Rendered HTML body from the content file
$content->slug- URL slug, e.g. blog/hello-world
$content->get($key, $default)- Safe accessor for any metadata value
Why Use a Repository?
- Abstraction — hide filesystem details behind a clean interface
- Testability — easy to mock or swap implementations
- Flexibility — change storage without changing calling code
- Single responsibility — one place handles all content loading
Under the Hood
- Maps the requested path to candidate file locations
- Walks up the directory tree collecting inherited metadata
- Loads and parses the content file
- Merges metadata — innermost wins
- Returns a structured
Contentobject
Core Methods
find()
Retrieve a single page by its path:
$repo = $container->get(ContentRepositoryInterface::class);
$page = $repo->find('/blog/hello-world');
if ($page) {
echo $page->title;
echo $page->body;
echo $page->get('author');
}
all()
List all content in a section:
// All content
$pages = $repo->all();
// Only blog posts
$posts = $repo->all('blog');
// Only Spanish content
$spanish = $repo->all('es');
Metadata Inheritance
Child pages automatically inherit metadata from their parent's index.php.
Example
// content/es/index.php
$meta = [
'language' => 'es',
'locale' => 'es-ES',
];
// content/es/algo.php
$meta = ['title' => 'Algo'];
// When loading /es/algo, metadata is merged:
// ['language' => 'es', 'locale' => 'es-ES', 'title' => 'Algo']
Content Objects
The repository returns Content objects with structured data:
$content->title // Page title
$content->body // Rendered HTML content
$content->slug // URL slug (e.g., 'blog/hello-world')
$content->meta // Array of all metadata
$content->get($key, $default) // Get specific metadata value
Why Use a Repository?
- Abstraction: Hide filesystem details behind a clean interface
- Testability: Easy to mock or create test implementations
- Flexibility: Swap implementations without changing calling code
- Consistency: All content access goes through one path
Under the Hood
The repository:
- Maps the requested path to potential file locations
- Walks up the directory tree collecting inherited metadata
- Loads and parses the content file
- Merges metadata with inheritance
- Returns a structured Content object