承接 getphred/scape 相关项目开发

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

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

getphred/scape

Composer 安装命令:

composer require getphred/scape

包简介

A Lightweight PHP Template Engine

README 文档

README

Latest Version on Packagist Total Downloads Software License

A lightweight, standalone PHP template engine designed for simplicity, security, and performance. Scape focuses on being an Output Engine first, marrying pre-processed data with design while enforcing a "logic-light" philosophy.

Features

  • Dot Notation & Bracket Access: Effortlessly access nested objects and arrays.
  • Inheritance & Blocks: Define base layouts and override sections in child templates.
  • Partials & Includes: Reuse template snippets with controlled data scoping.
  • Filter Pipeline: Transform data using built-in or custom filters (e.g., {{ var | lower | ucfirst }}).
    • Built-in filters: lower, upper, ucfirst, currency, float, date, truncate, default, json, url_encode, join, first, last, word_count, keys.
    • Filters can be used in variable interpolations, foreach loops, and include tags.
  • Secure by Default: Automatic contextual HTML escaping for all variables.
  • AST Caching: High performance via Abstract Syntax Tree caching with automatic dev-mode invalidation.
  • Host Integration (IoC): Easy integration with frameworks through the reserved host namespace.
  • Logic-Light: Encourages separation of concerns by supporting only necessary logic like foreach.

Installation

composer require getphred/scape

Quick Start

use Scape\Engine;

$engine = new Engine([
    'templates_dir' => __DIR__ . '/templates',
    'mode' => 'debug' // or 'production'
]);

echo $engine->render('index', [
    'title' => 'Welcome to Scape',
    'user' => ['name' => 'Funky']
]);

Basic Syntax

Interpolation (Escaped)

{{ user.name }}

Raw Interpolation

{{{ raw_html }}}

Loops

{( foreach item in items )}
    <li>{{ item }}</li>
{( endforeach )}

Filtering

{{ price | currency('USD') }}

Advanced Expressions

{( foreach key in user_data | keys )}

{[ include 'partial' with data | first ]}

Inheritance

layout.scape.php:

<html>
    <title>{[ block 'title' ]}Default Title{[ endblock ]}</title>
    <body>{[ block 'content' ]}{[ endblock ]}</body>
</html>

page.scape.php:

{[ extends 'layout' ]}
{[ block 'title' ]}My Page{[ endblock ]}
{[ block 'content' ]}
    <h1>Hello World</h1>
{[ endblock ]}

Configuration

Scape uses environment variables or programmatic configuration:

  • SCAPE_TEMPLATES_DIR: Default ./templates
  • SCAPE_LAYOUTS_DIR: Default ./templates/layouts
  • SCAPE_PARTIALS_DIR: Default ./templates/partials
  • SCAPE_FILTERS_DIR: Default ./filters
  • SCAPE_CACHE_DIR: Default ./.scape/cache
  • SCAPE_MODE: production (default) or debug

License

MIT

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-02-12

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固