https://github.com/naingaunglwin-dev/view
A lightweight template rendering engine with php
https://github.com/naingaunglwin-dev/view
render rendering-engine template-rendering view
Last synced: 5 months ago
JSON representation
A lightweight template rendering engine with php
- Host: GitHub
- URL: https://github.com/naingaunglwin-dev/view
- Owner: naingaunglwin-dev
- Created: 2024-02-03T06:40:01.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2024-12-22T12:12:37.000Z (over 1 year ago)
- Last Synced: 2025-08-01T01:09:04.807Z (11 months ago)
- Topics: render, rendering-engine, template-rendering, view
- Language: PHP
- Homepage:
- Size: 17.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
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](https://getcomposer.org/download/) first.
- create file `composer.json` at your project root directory.
- Add this to `composer.json`
```php
{
"require": {
"naingaunglwin-dev/view": "^1.0"
}
}
```
- Run the following command in your terminal from the project's root directory:
```bash
composer install
```
- Or just run `composer require naingaunglwin-dev/view` in terminal.
## Usage
- In your php file,
```php
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.php` and `two.php`
- one.php
```php
yield('content');
```
- two.php
```php
extends('one'); // view file name that need to extend
$this->section('content'); // Section start with `content` name
echo '
This is section content from two.php';
$this->end('content'); // End the section `content`
```
- index.php
```php
render('two');
```
- Output will be
```txt
this is one.php
This is section content from two.php
```
### Custom Renderer Engine
```php
render('template'); // MyCustomEngine`s render method will be used in this process if exists
```