azettl/php-nano-template

The php-nano-template class replaces placeholders in a string with values from an array.

0.0.5 2020-06-05 21:41 UTC

This package is auto-updated.

Last update: 2024-04-06 06:31:20 UTC


README

Codacy Badge

The php-nano-template class replaces placeholders in a string with values from an array.

Installation

composer require azettl/php-nano-template

Usage

$nano = new com\azettl\nano\template();
$nano->setTemplate(
  "<p>
    {user.greeting()} {user.function(2)} {user.function('test')} {user.first_name} {user.last name}! 
    Your account is <strong>{user.account.status}</strong> 
    {user.nonexistingnode}
  </p>"
);
$nano->setData($aData);
$nano->setShowEmpty(true);

echo $nano->render(); 

or

$nano = new com\azettl\nano\template(
  "<p>
    {user.greeting()} {user.first_name} {user.last name}! 
    Your account is <strong>{user.account.status}</strong> 
    {user.nonexistingnode}
  </p>",
  [
    "user" => [
      "login" => "demo",
      "first_name" => "Anon",
      "last name" => "Ymous",
      "account" => [
        "status" => "active",
        "expires_at" => "2016-12-31"
      ],
      "greeting" => function(){
        return 'Hello';
      },
      "function" => function($param){
        return 'Test' . $param;
      }
    ]
  ]
);

echo $nano->render(); 

or

$nano = new com\azettl\nano\template();
$nano->setTemplateFile(
  "tests/template.html"
);
$nano->setData($aData);

echo $nano->render();