PHPackages                             jijihohococo/ichi-template - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Templating &amp; Views](/categories/templating)
4. /
5. jijihohococo/ichi-template

ActiveLibrary[Templating &amp; Views](/categories/templating)

jijihohococo/ichi-template
==========================

PHP Template

2.4(2mo ago)0501MITPHPPHP &gt;=7.0 || &gt;=8.0CI passing

Since Feb 8Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/jijihohococo/ichi-template)[ Packagist](https://packagist.org/packages/jijihohococo/ichi-template)[ RSS](/packages/jijihohococo-ichi-template/feed)WikiDiscussions master Synced today

READMEChangelog (2)DependenciesVersions (11)Used By (1)

ICHI PHP TEMPLATE
=================

[](#ichi-php-template)

ICHI PHP TEMPLATE is the fast and secure Pure PHP Template Library

License
-------

[](#license)

This package is Open Source According to [MIT license](LICENSE.md)

Table Of Contents
-----------------

[](#table-of-contents)

- [ICHI PHP TEMPLATE](#ichi-php-template)
    - [License](#license)
    - [Table Of Contents](#table-of-contents)
        - [Acknowledgement](#acknowledgement)
        - [Installation](#installation)
        - [Set Up Template Base Directory Path](#set-up-template-base-directory-path)
        - [Showing Views](#showing-views)
        - [Showing Error Messages](#showing-error-messages)
        - [Showing Success Messages](#showing-success-messages)
        - [Section And Content](#section-and-content)
        - [Sharing Data In All Views](#sharing-data-in-all-views)
        - [Preventing XSS Attack](#preventing-xss-attack)
        - [Components](#components)
    - [Show Old Request Data](#show-old-request-data)

### Acknowledgement

[](#acknowledgement)

I really thanks to my mother for everything. She is the best for me.

### Installation

[](#installation)

```
composer require jijihohococo/ichi-template
```

### Set Up Template Base Directory Path

[](#set-up-template-base-directory-path)

You can set up the base directory path for your all template view files.

**It is highly recommend to set up template base directory path before using functions of ICHI TEMPLATE**

**The base directory path will be used in calling all views**

```
use JiJiHoHoCoCo\IchiTemplate\Template\View;

// example //

View::setPath(__DIR__.'/../views/');
```

It doesn't matter if you want to use another base directory path name.

After setting template base path for views, you can directly call the files under this base path directly.

For example,you have 'show\_data.php' under your template base path.

You can directly call this file in showing views directly without including directory path if you had set template base path.

### Showing Views

[](#showing-views)

You can show the views in your function like that

**You must include full directory path if you don't set up the template base path**

**Using 'view' function can only apply section and content template style in that called view php file.**

*Without Data*

```
public function showData(){
	//
	return view('show_data.php');
}
```

*With Data*

```
public function showData(){
	return view('show_data.php',[
		'data' => 'Hello World'
	]);
}
```

**You can also call your php file without '.php' file extension**

```
public function showData(){

	return view('show_data');
}
```

You can use called data in your view file which is calling from "view" function

*In your\_view\_php\_file\_path*

```
echo $data; // Hello World
```

If you don't want to use template system but want to show only the views. You can do as shown as below

You can also use following functions within your view php file which is called from 'view' function

*Without Data*

```
includeView('include_file.php');
```

*With Data*

```
includeView('include_file.php',[
	'data' => 'Hello World'
]);
```

**You can also call your php file without '.php' file extension**

```
includeView('include_file');
```

'includeView' function will show the file by using 'include' function 'includeOnceView' function will show the by using 'include\_once' function 'requireView' function will show the file by using 'require' function 'requireOnceView' function will show the file by using 'require\_once' function

### Showing Error Messages

[](#showing-error-messages)

You can add error messages

```
setErrors([
	'name_error' => 'name is required',
	'email_error' => 'email is required'
]);
```

You can get error messages with 'errors' array variable in your view php files

```
if(isset($errors['name_error'])){

echo $errors['name_error']. '';

}

if(isset($errors['email_error'])){

echo $errors['email_error'] . '';

}
```

### Showing Success Messages

[](#showing-success-messages)

You can add success messages

```
setSuccess([
	'message' => 'registeration is completed'
]);
```

You can get sucess messages with 'success' array variable in your view php views

```
if(isset($success['message'])){

echo $success['message'];

}
```

### Section And Content

[](#section-and-content)

You can apply template system as shown as below

Firstly, you must show your view php file

```
return view('show_data.php');
```

*In your template main php file*

```
>

```

*In your view php file*

```

Content

```

**You can also call your php file without '.php' file extension**

```
extend('main');
```

In your view php file, You must call your template main php file with 'extend' function firstly. You must add 'content' name in your 'section' function. After using 'section' function and write your frontend stuffs you must use 'endSection' function

In your template main php file, you must call 'y' function with the content name that you want to show.

Both view php file and main layout file will be shown.

If you want to change page title dynamicatlly according to view php file

*In your view php file*

```
section('content','Content Page');
```

*In your template main php file*

```

```

### Sharing Data In All Views

[](#sharing-data-in-all-views)

You can share the data (variables) in all your views

```
use JiJiHoHoCoCo\IchiTemplate\Template\View;

View::share([
'writer' => 'John',
'book' => 'New Book'
]);
```

And calling 'view' function

```
return view('show_data.php');
```

You can use the share data as variables in your view php file

```
echo $writer . '';
echo $book;
```

### Preventing XSS Attack

[](#preventing-xss-attack)

You can prevent your string data output from xss attack

```
echo e($data);
```

### Components

[](#components)

You can use class as your component to show view php files

*In your component class*

```
namespace App\Components;
use JiJiHoHoCoCo\IchiTemplate\Component\Component;

class TestComponent extends Component{

	public function render(){
		return view('componet_view.php');
	}
}
```

You can create the component class with the commandline.

Firstly you need to created the file named "ichi" under your project folder and use the below code in this file

```
#!/usr/bin/env php
