PHPackages                             awesome9/templates - 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. awesome9/templates

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

awesome9/templates
==================

Wrapper for WordPress Filesystem and Templates.

1.0.4(4y ago)032GPL-3.0-or-laterPHPPHP &gt;=5.6

Since May 7Pushed 4y ago1 watchersCompare

[ Source](https://github.com/AwesomeNine/Templates)[ Packagist](https://packagist.org/packages/awesome9/templates)[ RSS](/packages/awesome9-templates/feed)WikiDiscussions master Synced 1w ago

READMEChangelog (5)DependenciesVersions (6)Used By (0)

Template
========

[](#template)

[![Awesome9](https://camo.githubusercontent.com/3c0c2d9b4a52297ff7faaf49e147ee8e6e96e0f435b798a6215c2e50ebc6bde3/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f417765736f6d652d392d627269676874677265656e)](https://awesome9.co)[![Codacy Badge](https://camo.githubusercontent.com/c66cfd31994f729b8eef6ef0f5fad9cacdba75f96b98c7ae3f56bc5887083318/68747470733a2f2f6170692e636f646163792e636f6d2f70726f6a6563742f62616467652f47726164652f6432303634336336363038373461386362376231333938666361316439336266)](https://app.codacy.com/gh/AwesomeNine/Templates?utm_source=github.com&utm_medium=referral&utm_content=AwesomeNine/Templates&utm_campaign=Badge_Grade)[![Latest Stable Version](https://camo.githubusercontent.com/741d9b16aa333a8b2ae8fb764fe8e17018a236e728a4a63c5d1298c8247c09ad/68747470733a2f2f706f7365722e707567782e6f72672f617765736f6d65392f74656d706c617465732f762f737461626c65)](https://packagist.org/packages/awesome9/templates)[![PHP from Packagist](https://camo.githubusercontent.com/7e5bab19fce5b2a57814acd96db5abd467799dd71a957912b27a4ee75f0285e5/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f617765736f6d65392f74656d706c617465732e737667)](https://packagist.org/packages/awesome9/templates)[![Total Downloads](https://camo.githubusercontent.com/16b1a2a67441faaec5141b4b1e464c87415c3f48c36c8abd126fd498d1e3b15d/68747470733a2f2f706f7365722e707567782e6f72672f617765736f6d65392f74656d706c617465732f646f776e6c6f616473)](https://packagist.org/packages/awesome9/templates)[![License](https://camo.githubusercontent.com/f3284ba191688bd3cc107829aeed0d1b7fe97f86248d64d316edc5f97241eef7/68747470733a2f2f706f7365722e707567782e6f72672f617765736f6d65392f74656d706c617465732f6c6963656e7365)](https://packagist.org/packages/awesome9/templates)

 [![](https://camo.githubusercontent.com/e72fe54cc01d357369ab7a27a68374ede03bb213f4e368e9289ba6cfd528f7ee/68747470733a2f2f696d672e69636f6e73382e636f6d2f6e6f6c616e2f3235362f73746f636b732e706e67)](https://camo.githubusercontent.com/e72fe54cc01d357369ab7a27a68374ede03bb213f4e368e9289ba6cfd528f7ee/68747470733a2f2f696d672e69636f6e73382e636f6d2f6e6f6c616e2f3235362f73746f636b732e706e67)

📃 About Template
----------------

[](#-about-template)

This package provides ease of loading templates intended to be used within a plugin or theme and also provide a template system like WooCommerce.

The inspiration for the package comes from [Templates micropackage](https://github.com/micropackage/templates).

💾 Installation
--------------

[](#-installation)

```
composer require awesome9/templates
```

🕹 Usage
-------

[](#-usage)

First, you need to initialize your storage.

```
Awesome9\Templates\Storage::get()
	->set_basedir( dirname( __FILE__ ) )
	->set_baseurl( plugins_url( __FILE__ ) );
```

#### Case # 1: Random folders

[](#case--1-random-folders)

Let's assume your template tree looks like this:

```
my-plugin/
├── admin/
│   └── templates/
│      ├── notice.php
│      └── settings.php
└── frontend/
	└── templates/
	   ├── profile.php
	   └── welcome.php

```

In the above case we have two places with templates, let's define them as storages.

```
Awesome9\Templates\Storage::get()->add( 'admin', 'admin/templates' );
Awesome9\Templates\Storage::get()->add( 'frontend', 'frontend/templates' );
```

Then you can easily render template:

```
$template = new Awesome9\Templates\Template( 'frontend', 'author', [
	'author' => $user_name,
	'posts'  => get_posts( [ 'author' => $user_id ] ),
] );

$template->render();
```

The template file could look like this:

```
Howdy,
