A simple helper class to process variables and alternative strings. Based on Spintax by Jason Davis.
Install via Composer
composer require kovsky0/mini-templater
To get started you need to require mini-templater.php
<?php
require_once('vendor/autoload.php');
Processing alternatives:
<?php
$templater = new MiniTemplater;
$example = "This is an {{example.|exemplary usage of the class.}}";
echo $templater->process($example);
Processing alternatives recursively:
<?php
$templater = new MiniTemplater;
$example = "This is an {{example.|exemplary usage of {{the|my}} class.}}";
echo $templater->process($example);
Processing variables:
<?php
$templater = new MiniTemplater;
$example = "This is an [[example_text]]";
$variables = array("example_text" => "exemplary usage of the class.");
echo $templater->process($example, $variables);
Processing alternatives inside variables:
<?php
$templater = new MiniTemplater;
$example = "This is an [[example_text]]";
$variables = array("example_text" => "{{example.|exemplary usage of the class.}}");
echo $templater->process($example, $variables);