millancore/view-element
最新稳定版本:v0.1
Composer 安装命令:
composer require millancore/view-element
包简介
Template system without configuration or dependencies.
README 文档
README
This is a library for creating modular views in PHP, without configuration or dependencies.
- Slot
- Render
- Filters
Install
composer require millancore/view-element
Slot
You can create a template without defining the template body, it is passed by the view that will use it.
You can also make use of the helper functions vxSlot(), vxStart(...), vxEnd(), which will make it easier for you to define components with fewer lines of code.
template_list.php
<ul id="<?= $id ?? '' ?>"> <?= \Vx\View::slot() ?> </ul>
view.php
<?php Vx\View::start('template_list.php', [ 'id' => 'list']) ?> <li>Test parent element</li> <?php Vx\View::start('template_list.php', ['id' => 'sublist']) ?> <li>Test Child element</li> <li>Test Child element</li> <?php Vx\View::end(); ?> <li>Test Parent element</li> <?php Vx\View::end(); ?>
or using helpers functions
<?php VxStart('template_list.php', [ 'id' => 'list']) ?> <li>Test parent element</li> <?php VxStart('template_list.php', ['id' => 'sublist']) ?> <li>Test Child element</li> <li>Test Child element</li> <?php VxEnd(); ?> <li>Test Parent element</li> <?php VxEnd(); ?>
Html
<ul id="list"> <li>Test parent element</li> <ul id="sublist"> <li>Test Child element</li> <li>Test Child element</li> </ul> <li>Test Parent element</li> </ul>
Config (optional)
This will allow you to define a path where all the views will be
and not have to type .php as it will be added automatically.
bootstrap.php
$viewResolver = Vx\Resolver::getInstance(); $viewResolver->config(new Vx\Config([ 'viewDir' => __DIR__ . DIRECTORY_SEPARATOR . 'views', 'extension' => false ]));
Filters
the filters are very simple, they allow you to add registering methods that modify.
bootstrap.php
$viewResolver = Vx\Resolver::getInstance(); $viewResolver->addFilter('upper', fn($string) => strtoupper($string));
Use them
<h1> <?= VxFilter('mi name', 'upper') ?> </h1> <!-- MI NAME -->
统计信息
- 总下载量: 6
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-10-20