naingaunglwin-dev/view
最新稳定版本:1.0.1
Composer 安装命令:
composer require naingaunglwin-dev/view
包简介
A lightweight template rendering engine with optional custom view engine integration.
README 文档
README
Simple PHP View Library
Contributing
- This is an open-source library, and contributions are welcome.
- If you have any suggestions, bug reports, or feature requests, please open an issue or submit a pull request on the project repository.
Requirement
- PHP version 8.0 or newer is required
Installation & Setup
- You can just download the code from repo and use or download using composer.
Download Using Composer
- If you don't have composer, install composer first.
- create file
composer.jsonat your project root directory. - Add this to
composer.json
{
"require": {
"naingaunglwin-dev/view": "^1.0"
}
}
- Run the following command in your terminal from the project's root directory:
composer install
- Or just run
composer require naingaunglwin-dev/viewin terminal.
Usage
- In your php file,
<?php require_once "vendor/autoload.php"; use NAL\View\View; $view = new View(__DIR__ . '/views'); // You can pass view file without extension if it is php file $view->render('index', ['status' => 'success']); // You can also render other file, // You can retrieve the view without rendering, $indexView = $view->render('index.html', [], true); // You can also render multi views $view->render(['index.html, test']);
- If you don't define your view path, View class will automatically set the view path to your project root level
Section Usage
-
create
one.phpandtwo.php -
one.php
<?php //one.php echo 'this is one.php'; $this->yield('content');
- two.php
<?php //two.php $this->extends('one'); // view file name that need to extend $this->section('content'); // Section start with `content` name echo '<br>This is section content from two.php'; $this->end('content'); // End the section `content`
- index.php
<?php require_once "vendor/autoload.php"; use NAL\View\View; $view = new View(__DIR__ . '/views'); $view->render('two');
- Output will be
this is one.php This is section content from two.php
Custom Renderer Engine
<?php $view = new \NAL\View\View('path', MyCustomEngine::class); $view->render('template'); // MyCustomEngine`s render method will be used in this process if exists
统计信息
- 总下载量: 10
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-05-03