承接 phpolar/pure-php 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

phpolar/pure-php

最新稳定版本:3.1.4

Composer 安装命令:

composer require phpolar/pure-php

包简介

Pure PHP Templates

README 文档

README

Phpolar Logo

Pure PHP

Templating that's just PHP. That's it. Seriously.

Support using pure PHP templates with automatic XSS mitigation.

Coverage Status Version PHP Version Require Total Downloads Weekly Check

Table of Contents

  1. Installation
  2. Usage
  3. Example
  4. API Documentation

Installation

composer require phpolar/pure-php

Usage

$page = new Page();
$safeContext = new HtmlSafeContext($page);
$templateEng->render("path/to/template.php", $safeContext);
// or...
echo $templateEng->apply("path/to/template", $safeContext /* optional */);

Template Basename Only

// or...
echo $templateEng->apply("template", $safeContext /* optional */);
// or...
echo $templateEng->apply("template", $safeContext /* optional */);

The template engine will look for files with .php, .phtml, or .html extensions in src/templates directory relative to the current working directory.

Example 1

Pure PHP Templates

// template.php or template.phtml
<?php
(function (Page $view) {
?>
<!DOCTYPE html>
<html>
    <head>
        <style>
            body {
                font-family: <?= $view->font ?>;
                padding: 0;
                margin: 0;
            }
            form th {
                text-align: right;
            }
            form  td {
                text-align: left;
            }
            .container {
                background-color: <?= $view->backgroundColor ?>;
                padding: 20px 0 90px
            }
        </style>
    </head>
    <body style="text-align:center">
        <h1><?= $view->title ?></h1>
        <div class="container">
        </div>
    </body>
</html>
<?php
})($this);
// Page.php

class Page
{
    public string $title;

    public string $backgroundColor = "#fff";

    public string $font = "Arial";

    public function __construct(string $title)
    {
        $this->title = $title;
    }
}

API Documentation

Back to top

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-02-23