Skip to content

Reference Pages

Erika Heidi edited this page Jan 11, 2024 · 1 revision

Documentation pages should extend from the ReferencePage class (or implement ReferencePageInterface) and implement the following methods:

  • loadData - this method receives an optional $parameters array and should load any additional data required to build the page.
  • getName - must return a unique identifier that can be used later on to build only this type of page.
  • getContent - the actual content that will be saved.
  • getSavePath - the path where to save this file, to be used by the page builder.

It is easier to see how it works in practice, so this is what the ExamplePage looks like:

<?php

declare(strict_types=1);

namespace Autodocs\Page;

use Autodocs\DataFeed\JsonDataFeed;

class ExamplePage extends ReferencePage
{
    public JsonDataFeed $dataFeed;
    public function loadData(array $parameters = []): void
    {
        $this->dataFeed = new JsonDataFeed();
        $this->dataFeed->loadFromArray([
            'title' => 'example',
            'description' => 'description'
        ]);
    }

    public function getName(): string
    {
        return "example";
    }

    public function getContent(): string
    {
        return $this->dataFeed->json['title'].' - '.$this->dataFeed->json['description'];
    }

    public function getSavePath(): string
    {
        return 'example.md';
    }
}

This example creates a JsonDataFeed and loads it with static data. Instead, you could use JSON data files and have them automatically loaded by Autodocs - you just need to place the files in the path defined by the cache configuration option.

Clone this wiki locally