kovsky0/mini-templater

A simple helper class to process variables and alternative strings

dev-master 2017-11-27 12:41 UTC

This package is not auto-updated.

Last update: 2024-06-03 05:56:43 UTC


README

A simple helper class to process variables and alternative strings. Based on Spintax by Jason Davis.

Installation

Install via Composer

composer require kovsky0/mini-templater

Getting started

To get started you need to require mini-templater.php

<?php
require_once('vendor/autoload.php');

How to use it

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);