t3docs/fluid-documentation-generator
Generates automatic TYPO3 Fluid ViewHelper reference documentation in RST. Configured via JSON files, it builds navigable RST pages plus a JSON index for Fluid namespaces and ViewHelpers, ready to render with TYPO3 render-guides.
Install the package in your Laravel/TYPO3 project (though primarily TYPO3-focused, it can be adapted for Laravel with Fluid integration):
composer require --dev t3docs/fluid-documentation-generator
Create a basic config file (e.g., viewhelpers_config.json) adhering to the JSON schema:
{
"name": "MyLaravelExtension",
"namespaceAlias": "laravel",
"targetNamespace": "http://typo3.org/ns/Vendor/MyLaravelExtension/ViewHelpers"
}
Run the generator (adjust paths as needed):
vendor/bin/fluidDocumentation generate path/to/viewhelpers_config.json
fluidDocumentationOutput/ by default (customizable via FLUID_DOCUMENTATION_OUTPUT_DIR).Render the RST using render-guides or Sphinx.
Annotate your ViewHelper with PHPDoc (critical for metadata extraction):
namespace Vendor\MyLaravelExtension\ViewHelpers;
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
/**
* Renders a formatted greeting.
*
* = Examples =
*
* <code title="Basic">
* {my:greeting(name: 'John')}
* </code>
* <output>
* Hello, John!
* </output>
*
* @api
*/
class GreetingViewHelper extends AbstractViewHelper
{
public function render(): string
{
return 'Hello, ' . htmlspecialchars($this->arguments['name']);
}
}
Generate docs:
vendor/bin/fluidDocumentation generate viewhelpers_config.json
Verify output:
fluidDocumentationOutput/MyLaravelExtension/GreetingViewHelper.rst for auto-generated RST.MyLaravelExtension.json) for dynamic rendering (e.g., with render-guides).Add a step to auto-generate docs on main branch pushes or PR merges:
- name: Generate Fluid Documentation
run: |
composer require --dev t3docs/fluid-documentation-generator
vendor/bin/fluidDocumentation generate config/viewhelpers_*.json
git add fluidDocumentationOutput/
git diff --quiet || git commit -m "chore: update Fluid docs [skip ci]"
For Laravel extensions with multiple ViewHelper packages:
# Generate docs for all configs in sequence (order matters for index page)
vendor/bin/fluidDocumentation generate \
config/viewhelpers_core.json \
config/viewhelpers_utils.json \
config/viewhelpers_ui.json
Set via environment variable (e.g., in .env or CI):
export FLUID_DOCUMENTATION_OUTPUT_DIR=docs/viewhelpers
vendor/bin/fluidDocumentation generate config/*.json
If using laravel-fluid or similar:
app/ViewHelpers/).{
"name": "LaravelApp",
"namespaceAlias": "app",
"targetNamespace": "http://typo3.org/ns/App/ViewHelpers"
}
Leverage Laravel’s existing PHPDoc standards for consistency:
/**
* Renders a paginated list.
*
* @param array $items The items to paginate.
* @param int $perPage Items per page (default: 10).
* @return string Rendered pagination HTML.
*
* @see \Vendor\MyLaravelExtension\ViewHelpers\PaginationViewHelper
*/
class PaginationViewHelper extends AbstractViewHelper
Force custom anchors for RST links (useful for Laravel’s route-based docs):
{
"headlineAnchor": "laravel-pagination"
}
Use config to skip internal/undocumented helpers:
{
"exclude": [
"Vendor\\MyLaravelExtension\\ViewHelpers\\Internal*"
]
}
Override default RST templates (located in vendor/t3docs/fluid-documentation-generator/src/Resources/templates/):
config/fluid-documentation-templates/.{
"templateDir": "config/fluid-documentation-templates/"
}
PHPDoc Requirements
@api tag: ViewHelpers without @api in PHPDoc are ignored.
Fix: Add @api to all public ViewHelpers.@param/@return reduces generated metadata.
Fix: Use PHPStorm’s PHPDoc generator for quick fixes.Namespace Mismatches
No ViewHelpers found in namespace.
Cause: targetNamespace in config doesn’t match the PHP namespace.
Fix: Verify the namespace in composer.json autoloading and config.RST Rendering Issues
Unknown directive 'fluid-viewhelper'.
Cause: Missing render-guides or Sphinx extension.
Fix: Install render-guides or use a Sphinx extension like sphinxcontrib-fluid.Output Directory Permissions
Failed to write to output directory.
Fix: Ensure FLUID_DOCUMENTATION_OUTPUT_DIR is writable:
mkdir -p docs/viewhelpers && chmod -R 777 docs/viewhelpers
Dry Run Mode
Use --dry-run to preview changes without writing files:
vendor/bin/fluidDocumentation generate --dry-run config/*.json
Verbose Logging Enable debug output:
vendor/bin/fluidDocumentation generate -v config/*.json
Validate Config Use the JSON schema validator:
composer require justinrainbow/json-schema
vendor/bin/json-schema-validator validate src/Config.schema.json config/viewhelpers_config.json
Custom Metadata Extraction
Extend the generator by subclassing TYPO3\Documentation\Fluid\ViewHelper\ViewHelperFinder and overriding findViewHelpers() to include Laravel-specific logic (e.g., parsing Blade directives).
Post-Processing Hooks
Use Laravel’s post-autoload-dump event to trigger doc generation:
// In a service provider
$this->app->booted(function () {
Artisan::call('fluidDocumentation:generate', [
'config' => [base_path('config/viewhelpers.json')],
]);
});
JSON Output Integration
Parse the generated JSON (MyPackage.json) in Laravel for dynamic API docs:
$viewHelpers = json_decode(file_get_contents(docs_path('MyPackage.json')), true);
// Use in a controller or Blade component
Autoloading ViewHelpers
Ensure ViewHelpers are autoloaded in composer.json:
{
"autoload": {
"psr-4": {
"Vendor\\MyLaravelExtension\\ViewHelpers\\": "app/ViewHelpers/"
}
}
}
Fluid Standalone in Laravel If using Fluid Standalone, install it as a dev dependency:
composer require --dev typo3/fluid
Cross-Referencing Laravel Routes Customize RST templates to link to Laravel’s route names:
:fluid-viewhelper:`Vendor\\MyLaravelExtension\\ViewHelpers\\GreetingViewHelper`
<https://laravel-app.test/greeting>
How can I help you explore Laravel packages today?