Search by

leonickl / plate

leonickl

There is no license information available for the latest version (v2.2.0) of this package.

A PHP templating engine

Package info

github.com/leonickl/plate

pkg:composer/leonickl/plate

Statistics

Installs: 228

Dependents: 1

Suggesters: 0

Stars: 0

Open Issues: 0

v2.2.0 2026-11-23 08:53 UTC

This package is auto-updated.

Last update: 2026-11-23 08:54:43 UTC


README

Plate

Plate

A lightweight PHP templating engine inspired by Laravel's Blade.

Features

  • Simple, expressive syntax with {{ }} delimiters
  • Automatic output escaping for security
  • Conditional rendering with if, elif, and else
  • Loop support with each
  • Raw PHP execution within templates
  • Compiles to plain PHP for optimal performance

Requirements

  • PHP >= 8.4

Installation

composer require leonickl/plate

Usage

<?php

require 'vendor/autoload.php';

use LeoNickl\Plate\Plate;

// Compile a .plate file to PHP code
$phpCode = Plate::file('view.plate');

// Cast to string to get the compiled PHP
echo (string) $phpCode;

Template Syntax

Printing Values

{{ "hello" }}              // Escaped output
{{ % $html }}              // Unescaped output
{{ "hello", "world" }}     // Multiple expressions (joined with space)

Execute PHP statement

{{ :$var = "test" }}       // Execute PHP without printing

Conditionals

{{ if: $condition }}
    <p>Yes!</p>
{{ elif: $other }}
    <p>Maybe!</p>
{{ else: }}
    <p>No!</p>
{{ if; }}

Loops

{{ each: $items as $item }}
    <p>{{ $item }}</p>
{{ each; }}

JSON

You can print out JSON directly into your js blocks. Adding flags is supported in the second argument. Some default args are provided for escaping special chars. You can override them with the third argument if you want to.

{{ json: ['<h3>escaped</h3>', 'this is pretty'], JSON_PRETTY_PRINT }}
{{ json: ['<h3>unescaped</h3>', 'this as well'], JSON_PRETTY_PRINT, override: true }}
{{ json: ['<h3>escaped</h3>', 'this not'] }}

Import Components

{{ plug: 'nav' }}
{{ plug: 'person', data: $person }}

In order for this to work, you need to define this function and adjust it to your environment:

function plug_plate(string $file, mixed ...$params): string
{
    return view($file, $params); // or however you import your views
}

Example

See example.plate for a complete example. Run it with:

php index.php | php

This compiles the template and executes the resulting PHP.

Syntax Highlighting

Available for VSCode leonickl/plate-vscode