Skip to content

This extension adds the Twig Template Engine to MediaWiki. This extension does nothing on its own and is meant to be a dependency of other extensions.

License

Notifications You must be signed in to change notification settings

Wikia/mediawiki-extensions-Twiggy

Repository files navigation

Twiggy

This extension adds the Twig Template Engine to MediaWiki. This extension Does nothing on its own and is meant to be a dependency of other extensions.

Install

  1. Add the extension into extensions/Twiggy in your MediaWiki installation.
  2. Add the Twiggy composer.json to composer.local.json:
{
	"extra": {
		"merge-plugin": {
			"include": [
				...,
				"extensions/Twiggy/composer.json"
			]
		}
	}
}
  1. Run composer update.
  2. Add this code block to the bottom of the LocalSettings.php file:
wfLoadExtension('Twiggy');

Usage

  1. Add Twiggy as a required extension in extension.json:
{
	...
	"requires": {
		"extensions": {
			"Twiggy": ">= 0.0.1"
		},
		"MediaWiki": ">= 1.31.0"
	}
	...
}
  1. Add a hook for SpecialPageBeforeExecute:
{
	"Hooks": {
		"SpecialPageBeforeExecute": "MyExtensionHooks::onSpecialPageBeforeExecute"
	}
}
  1. Define the hook to register the template location:
public static function onSpecialPageBeforeExecute( SpecialPage $special, $subPage ) {
	$twig = MediaWikiServices::getInstance()->getService( 'TwiggyService' );
	$twig->setTemplateLocation('MyExtensionName', __DIR__ . '/../resources/templates');
}
  1. Example Special Page Usage:
public function execute($subpage) {
	...
	$twig = MediaWikiServices::getInstance()->getService( 'TwiggyService' );
	$template = $twig->load('@MyExtensionName/template.twig');
	$this->output->addHtml($template->render(['title' => $title, 'types' => $types]));
}
  1. Example Template template.twig
<h1>{{ wfMessage('title_language_key', 'plain') }}</h1>
<ul>
{% for id, type in types %}
	<li id="type_{{ id }}>{{ type.title }}</li>
{% endfor %}
</ul>

wfMessage in Twig

Twiggy has a pass-through function for wfMessage() support. In templates all arrow methods are converted to dot syntax.

{{ wfMessage(string $msg).plain() }}

About

This extension adds the Twig Template Engine to MediaWiki. This extension does nothing on its own and is meant to be a dependency of other extensions.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published