michel/pure-plate 问题修复 & 功能扩展

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

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

michel/pure-plate

最新稳定版本:1.0.0

Composer 安装命令:

composer require michel/pure-plate

包简介

PurePlate is a lightweight and versatile template rendering library for native PHP.

README 文档

README

PurePlate is a lightweight and versatile template rendering library for native PHP.

Installation

You can install the library using Composer. Just run the following command:

composer require michel/pure-plate

Basic Usage

To use the renderer in your project, first create an instance of the PhpRenderer class and pass the directory where your templates are located.

use Michel\Renderer\PurePlate;

// Specify the template directory
$templateDir = '/path/to/templates';

// Optional global variables to be passed to all templates
$globals = [
    'siteTitle' => 'My Website',
];

// Create the renderer instance
$renderer = new PurePlate($templateDir, $globals);

Creating a Layout

Create a layout file (e.g., layout.php) that represents the common structure of your pages. Use block() to define sections that will be replaced by content from child templates.

<!DOCTYPE html>
<html>
<head>
    <title><?php echo $this->block('title'); ?></title>
</head>
<body>
    <div class="container">
        <?php echo $this->block('content'); ?>
    </div>
</body>
</html>

Creating a Template

Create your template file (e.g., page.php). Use extend() to specify the layout file and startBlock() / endBlock() to define the content for the blocks.

<?php $this->extend('layout.php'); ?>

<?php $this->startBlock('title'); ?>
    My Page Title
<?php $this->endBlock(); ?>

<?php $this->startBlock('content'); ?>
    <h1>Hello, <?php echo $name; ?>!</h1>
    <p>Welcome to my website.</p>
<?php $this->endBlock(); ?>

Rendering Templates

To render your template, use the render method. You can pass an array of variables to be extracted and made available within the template.

echo $renderer->render('page.php', ['name' => 'John']);

This will render page.php, inject its blocks into layout.php, and return the final HTML.

Contributing

Contributions to the PurePlate library are welcome! If you find any issues or want to suggest enhancements, feel free to open a GitHub issue or submit a pull request.

License

PurePlate is open-source software released under the MIT License. See the LICENSE file for more details.

统计信息

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

GitHub 信息

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

其他信息

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