millancore / view-element
Template system without configuration or dependencies.
Installs: 6
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/millancore/view-element
Requires
- php: >=7.4
- ext-json: *
Requires (Dev)
- pestphp/pest: v1.22.1
- phan/phan: 5.4.1
- symfony/var-dumper: ^5.3
This package is auto-updated.
Last update: 2025-10-20 22:06:13 UTC
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 -->