leonickl/plate
Composer 安装命令:
composer require leonickl/plate
包简介
A PHP templating engine
README 文档
README
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, andelse - 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; }}
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
统计信息
- 总下载量: 107
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: Unknown
- 更新时间: 2026-04-07