php-compatible/templates 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

php-compatible/templates

最新稳定版本:v1.0.0

Composer 安装命令:

composer require php-compatible/templates

包简介

Modern PHP-style templating that works on PHP 5.5+

README 文档

README

CI codecov PHP Version License

Blazing fast PHP templating with zero dependencies.

A lightweight, high-performance template engine that leverages PHP's native output buffering for maximum speed. No parsing overhead, no compilation step, no caching layer needed - just pure PHP execution at full speed.

Why templates?

  • Zero overhead - Uses PHP's native require and output buffering. No regex parsing, no AST compilation, no runtime interpretation.
  • Instant rendering - Templates execute as native PHP code. What you write is what runs.
  • No dependencies - A single function. No framework required. No external libraries.
  • Legacy compatible - Works on PHP 5.5 through 8.x. Modernize your legacy codebase without breaking compatibility.
  • Familiar syntax - It's just PHP. No new template language to learn.

Documentation

Full documentation available at phpcompatible.dev/docs/category/templates

Installation

composer require php-compatible/templates

Quick Start

Create a template file views/hello.php:

<h1><?php echo $title; ?></h1>
<p><?php echo $message; ?></p>

Render it:

<?php
require 'vendor/autoload.php';

$html = template('views/hello.php', array(
    'title' => 'Hello World',
    'message' => 'Welcome to my site!'
));

echo $html;

Examples

Loops

<!-- views/list.php -->
<ul>
<?php foreach ($items as $item): ?>
    <li><?php echo $item; ?></li>
<?php endforeach; ?>
</ul>
$html = template('views/list.php', array(
    'items' => array('Apple', 'Banana', 'Cherry')
));

Nested Data

<!-- views/user.php -->
<div class="user-card">
    <h2><?php echo $user['name']; ?></h2>
    <p><?php echo $user['email']; ?></p>
</div>
$html = template('views/user.php', array(
    'user' => array(
        'name' => 'John Doe',
        'email' => 'john@example.com'
    )
));

HTML Escaping

The template() function does not automatically escape output. For security, use htmlspecialchars():

<h1><?php echo htmlspecialchars($title, ENT_QUOTES, 'UTF-8'); ?></h1>

API

template($path, $variables)

Renders a PHP template file and returns the output as a string.

Parameter Type Description
$path string Path to the template file
$variables array Associative array of variables available in the template

Returns: string - The rendered template output

Requirements

  • PHP 5.5 or higher

License

MIT

统计信息

  • 总下载量: 2
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-12-30

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固