michalsn/codeigniter-markdown-pages

Markdown pages for CodeIgniter 4 framework

v1.0.0 2023-11-14 15:05 UTC

This package is auto-updated.

Last update: 2024-11-18 03:15:49 UTC


README

Markdown based pages for the CodeIgniter 4 framework.

PHPUnit PHPStan Deptrac Coverage Status

PHP CodeIgniter

Installation

composer require michalsn/codeigniter-markdown-pages

Basic usage

To easily demonstrate how the things are working we will assume for a moment that this is our folder structure.

├── app
├── content
│   ├── 1_quick-start
│   │   ├── 1_installation.md
│   │   ├── 2_database-migration.md
│   │   ├── what-next.md
│   │   └── subfolder
│   │       └── one-file.md
│   └── first-steps
│       ├── available-methods.md
│       └── how-to-use-this.md
├── public
├── tests
├── vendor
└── writable

Now we have to initialize Markdown Pages with our folder:

$markdownPages = services('markdownpages', ROOTPATH . 'content');

$dir = $markdownPages->dirs()->first();

echo $dir->getName()
// prints: Quick Start

echo $dir->getSlug()
// prints: quick-start

foreach($dir->getFiles()->items() as $file) {
    echo $file->getName();
    // prints: Installation

    echo $file->getSlug();
    // prints: installation

    echo $file->getPath();
    // prints: quick-start/installation

    echo $content->parse()->getContent();
    // prints: parsed markdown from file

    echo $content->parse()->getMeta();
    // prints: parsed YAML as key -> value
}

We use Collection class pretty much everywhere so please get familiar with it to use this package comfortably.

Docs

https://michalsn.github.io/codeigniter-markdown-pages/