shineunited/conductor-twig-addon

Addon for Conductor to support building files using Twig templates.

Installs: 3 430

Dependents: 1

Suggesters: 0

Security: 0

Stars: 0

Watchers: 5

Forks: 0

Open Issues: 0

Type:composer-plugin

1.0.0 2022-11-23 20:39 UTC

This package is auto-updated.

Last update: 2024-10-24 00:54:31 UTC


README

License Latest Version PHP Version Main Status Release Status Develop Status

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')
		];
	}
}