shineunited / conductor-twig-addon
Addon for Conductor to support building files using Twig templates.
Installs: 3 560
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 5
Forks: 0
Open Issues: 0
Type:composer-plugin
Requires
- php: >=8.0
- composer-plugin-api: ^2.0
- shineunited/conductor: ^1.0
- symfony/filesystem: ^6.0
- twig/twig: ^3.4
Requires (Dev)
- composer/composer: ^2.4
- phpcompatibility/php-compatibility: ^9.3
- phpstan/phpstan: ^1.9
- phpunit/phpunit: ^9.5
- shineunited/coding-standard: ^1.0
- squizlabs/php_codesniffer: ^3.0
README
Description
Add support for Twig templates to the Conductor generator/blueprint framework.
Installation
To add conductor-twig-addon, the recommended method is via composer.
$ composer require shineunited/conductor-twig-addon
Usage
NamespaceProvider Capability
The NamespaceProvider capability registers Twig template include paths.
Example Plugin
The plugin must implement Capable and provide the NamespaceProvider capability.
<?php namespace Example\Project; use Composer\Composer; use Composer\IO\IOInterface; use ShineUnited\Conductor\Addon\Twig\Capability\NamespaceProvider; use ShineUnited\Conductor\Capability\BlueprintProvider; class ComposerPlugin implements PluginInterface, Capable { public function activate(Composer $composer, IOInterface $io): void { // ... } public function deactivate(Composer $composer, IOInterface $io): void { // ... } public function uninstall(Composer $composer, IOInterface $io): void { // ... } public function getCapabilities(): array { return [ NamespaceProvider::class => ExampleNamespaceProvider::class, BlueprintProvider::class => ExampleBlueprintProvider::class ]; } }
Example Provider
The provider must implement the capability, and return a list of TwigNamespaceInterface objects.
<?php namespace Example\Project; use ShineUnited\Conductor\Addon\Twig\Capability\NamespaceProvider; use ShineUnited\Conductor\Addon\Twig\Loader\TwigNamespace; class ExampleNamespaceProvider implements NamespaceProvider { public function getNamespaces(): array { return [ new TwigNamespace('path/to/template/dir', 'optional-namespace'), new TwigNamespace('path/to/global/templates') // load in root namespace ]; } }
These namespaces can then be used in a blueprint provider with the TwigBlueprint.
<?php namespace Example\Project; use ShineUnited\Conductor\Capability\BlueprintProvider; use ShineUnited\Conductor\Addon\Twig\Blueprint\TwigBlueprint; class ExampleBlueprintProvider implements BlueprintProvider { public function getBlueprints(): array { return [ new TwigBlueprint('path/to/file.html', '@namespace/template.twig'), new TwigBlueprint('another/file.html', 'global.twig') ]; } }