pkit/phantom
最新稳定版本:v0.1.1
Composer 安装命令:
composer require pkit/phantom
包简介
A simple module to handle views
README 文档
README
A simple module to handle views
Installation
Using Composer, enter the following command:
composer require pkit/phantom
Usage
Rendering
Initially, the page is rendered through the static class Pkit\Phantom.
use Pkit\Phantom; use Pkit\View; # ".\view" is the default directory, and views are discovered without file extension return Phantom::render("page", ["var" => $value]); /***/ return Phantom::renderView(new View(/* path */), "dir/page");
Pages
The page is written in vanilla PHP, and the extension used is .phtml, which cannot be modified.
<? use Pkit\Phantom ?> <? /* Passed variables are already converted */ ?> <?= $var ?> <? /* Views from other folders are supported */ ?> <?= Phantom::renderView(new View(/* path */), "dir/page") ?>
Components
# ./view/component.phtml component <?= $var ?>
To add components, the include method is basically used.
# ./view/master.phtml <? use Pkit\Phantom ?> <?= Phantom::include("component", ["var" => 1]) ?>
Sections
It is possible to create templates using the slot syntax.
# ./view/master.phtml <? use Pkit\Phantom ?> <? //* Slots must have unique keys to avoid conflicts */ ?> <tag> <?= Phantom::slot("slot_1") ?> </tag> <?= Phantom::slot("slot_2") ?>
To use them on the page, you should extend the view and thus, by wrapping the sections, they will be delivered to the slots.
<? use Pkit\Phantom ?> <? Phantom::extend("master")?> <? Phantom::section("slot_1") ?> # text... <? Phantom::stop() ?> # The text in these intervals will be ignored # Note: the code in this area will still be executed <? Phantom::section("slot_2") ?> # text... <? Phantom::stop() ?>
统计信息
- 总下载量: 25
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-02-15