PHPackages                             joseym/li3\_hierarchy - 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. joseym/li3\_hierarchy

ActiveLithium-library[Templating &amp; Views](/categories/templating)

joseym/li3\_hierarchy
=====================

A Lithium PHP plugin to allow for template inheritance. It's slick.

103192[4 issues](https://github.com/joseym/li3_hierarchy/issues)PHP

Since Aug 8Pushed 12y ago3 watchersCompare

[ Source](https://github.com/joseym/li3_hierarchy)[ Packagist](https://packagist.org/packages/joseym/li3_hierarchy)[ RSS](/packages/joseym-li3-hierarchy/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependenciesVersions (2)Used By (0)

[Lithium PHP](http://lithify.me) Plugin to allow for savvy template inheritance
===============================================================================

[](#lithium-php-plugin-to-allow-for-savvy-template-inheritance)

---

> Don't get too excited, this project has only just started and it's currently fairly rough

---

Installation
------------

[](#installation)

### Use Composer

[](#use-composer)

**It's like pie... In that it's awesome, and so is pie!**

> New to Composer? Have no fear, it's easy and well worth taking on: [This will help](https://github.com/composer/composer#installation--usage).

Modify your projects `composer.json` file

```
{
    "require": {
    	...
        "joseym/li3_hierarchy": "master"
        ...
    }
}
```

Run `php composer.phar install` (or `php composer.phar update`) and, aside from adding it to your Libraries, you should be good to go.

### Clone, Download, or Submodule

[](#clone-download-or-submodule)

**Old Timey Way**

1. Clone/Download/submodule the plugin into your app's `libraries` directory.
2. Tell your app to load the plugin by adding the following to your app's `config/bootstrap/libraries.php`:

Usage
-----

[](#usage)

Add the plugin in your `config/bootstrap/libraries.php` file:

```

```

With this plugin you no longer assign views to layouts the same way as with core lithium templates.

#### Originial Method

[](#originial-method)

**Your Layout**

```

	...

		...

		...

```

> This method blocks a single section in your layout, all content that reside within views will end up here.
>
> > While I dont think this is technically *bad* it does seem a bit limiting

#### Hierarchical method

[](#hierarchical-method)

**Your Layout**

`layouts/default.html.php`

```

	...

		...
		{:block "content"}Default Content{block:}
		{:block "sidebar"}Default Sidebar{block:}
		...

```

> So here we have set 2 sections, `content` and `sidebar`. We can change these sections anytime from any view.

Here's how

**Home View**

`pages/home.html.php`

```
{:parent "layout/default.html.php":}

{:block "content"}
	Welcome to My site!
	This is my home page, please wipe your feet.
{block:}

{:block "sidebar"}

		About Me
		My Github Profile

{block:}
```

So you read this and think to yourself ... "ok, what's so special about that?"

**quit heckling, heckler!**

Now you want to create that "About Me" page. Because time is short and you're eager to go eat a sandwich you've decided that, for now, the only difference between it and the home page is the sidebar. You don't want it to show the link to the "About Me" page, but rather show the link to the "Home" page. ("wow, baffling example Josey!")

Well, rather than rewriting that page you simply assign it's parent to the home page and modify the sidebar block:

**About Me**

`pages/about.html.php`

```
{:parent "pages/home.html.php":}

{:block "sidebar"}

		Home
		My Github Profile

{block:}
```

> Ok, I realize this is a painfully simple example but I hope it gets the point across.

This becomes especially useful when dealing with large, complicated project, when certain pages only modify a section or two.

#### Other Features

[](#other-features)

This plugin gives you the ability to include content from parent/child templates wherever you'd like them.

##### Parent Requests

[](#parent-requests)

**About Me**

`pages/about.html.php`

```
{:parent "pages/home.html.php":}

{:block "sidebar"}
	{:parent:}

		Home
		My Github Profile

{block:}
```

The `{:parent:}` line above tells the renderer to load the content that is stored within `pages/home.html.php` block `sidebar` above the content you are assigning in `pages/about.html.php` block `sidebar`.

You can also optionally force the parent to use the rendering, namely specialized paths, for a specifc type (layout/template). To do so specify layout/template directly after :parent.

```
{:parent layout "pages/home":}
```

##### Child Requests

[](#child-requests)

Similar to the above example: you can place child content from parents

**Home Page**

`pages/home.html.php`

```
{:parent "pages/default.html.php":}

{:block "sidebar"}

		Home
		My Github Profile

	{:child"}
{block:}
```

Now whatever you add in the `sidebar` block within the `pages/about.html.php` template will be loaded in after the content that resides in the `sidebar` block of the `pages/home.html.php` template!

##### Wrapping Blocks

[](#wrapping-blocks)

There will be times when you may want to load child content within markup but not load that markup if no child exists.

Here is how you accomplish that. It's easy!

**Home Page**

`pages/home.html.php`

```
{:parent "pages/default.html.php":}

{:block "advert"}

	{:child"}

{block:}
```

Like in the `child` example above this will load whatever content you assign within the `advert` block from any child templates (templates that assign `pages/home.html.php` as their parent).

What happens if a page that extends `pages/home.html.php` doesn't have an `advert` block? The entire block is removed! If you assign an `advert` block from a child, however, the contents will be loaded within the `` markup.

Some Notes
----------

[](#some-notes)

1. This project currently uses similar formatting to many "PHP Template Engines", but is not, in fact, a template engine itself. You would go about every other lithium layout/view effort exactly as before. This project only attempts to meet a need to offer more power and inheritance to the rendering method of views.
2. This project was inspired while I worked a plugin to provide [Smarty PHP support for Lithium](https://github.com/joseym/li3_smarty) project. (blech)! As I can't stand working with PHP Template Engines but actually think Smarty's template inheritance is a good idea I decided to attempt to achieve/improve upon it without being stuck with the limitations that Smarty enforces.

Plans for the future
--------------------

[](#plans-for-the-future)

1. I plan for this plugin to be able to handle blocks defined and modified from within other blocks, currently it does not support this.
2. Caching: I need to figure out a good way to cache the ladder of templates but still know when a modification was made.

Collaborate
-----------

[](#collaborate)

As always, I welcome your collaboration to make things "even more betterer", so fork and contribute if you feel so inclined.

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance12

Infrequent updates — may be unmaintained

Popularity20

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity43

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/4bf26971c193ef51e8682115d4cc161f914e0beceb47a2c7f02a40c3f2cb6ba2?d=identicon)[joseym](/maintainers/joseym)

---

Top Contributors

[![joseym](https://avatars.githubusercontent.com/u/238732?v=4)](https://github.com/joseym "joseym (68 commits)")

### Embed Badge

![Health badge](/badges/joseym-li3-hierarchy/health.svg)

```
[![Health](https://phpackages.com/badges/joseym-li3-hierarchy/health.svg)](https://phpackages.com/packages/joseym-li3-hierarchy)
```

###  Alternatives

[mustache/mustache

A Mustache implementation in PHP.

3.3k44.6M291](/packages/mustache-mustache)[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9682.1M97](/packages/roots-acorn)[whitecube/nova-flexible-content

Flexible Content &amp; Repeater Fields for Laravel Nova.

8053.0M25](/packages/whitecube-nova-flexible-content)[mopa/bootstrap-bundle

Easy integration of twitters bootstrap into symfony2

7042.9M33](/packages/mopa-bootstrap-bundle)[limenius/react-bundle

Client and Server-side react rendering in a Symfony Bundle

3871.2M](/packages/limenius-react-bundle)[nicmart/string-template

StringTemplate is a very simple string template engine for php. I've written it to have a thing like sprintf, but with named and nested substutions.

2101.7M30](/packages/nicmart-string-template)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
