PHPackages                             memdev/silverstripe-templatehooks - 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. memdev/silverstripe-templatehooks

ActiveSilverstripe-module[Templating &amp; Views](/categories/templating)

memdev/silverstripe-templatehooks
=================================

TemplateHooks enables developers to hook into user (=developer) defined hook points within SilverStripe template files.

1.0.1(10y ago)0141BSD-3-ClausePHP

Since Apr 17Pushed 10y ago2 watchersCompare

[ Source](https://github.com/memdev/silverstripe-templatehooks)[ Packagist](https://packagist.org/packages/memdev/silverstripe-templatehooks)[ Docs](https://github.com/memdev/silverstripe-templatehooks)[ RSS](/packages/memdev-silverstripe-templatehooks/feed)WikiDiscussions master Synced today

READMEChangelog (1)Dependencies (1)Versions (3)Used By (0)

Template Hooks for SilverStripe
===============================

[](#template-hooks-for-silverstripe)

A simple template hook system for SilverStripe.

[![Latest Stable Version](https://camo.githubusercontent.com/da44de626f9780ec30e0cb27b9ad9c9e11f5b9eabd37fdd648d9a8947b0457d8/68747470733a2f2f706f7365722e707567782e6f72672f6d656d6465762f73696c7665727374726970652d74656d706c617465686f6f6b732f762f737461626c653f666f726d61743d666c6174)](https://packagist.org/packages/memdev/silverstripe-templatehooks)[![Total Downloads](https://camo.githubusercontent.com/accc1183031d1d85953232a134709df868ac6bcf409e05ad767ebfc2069e32b6/68747470733a2f2f706f7365722e707567782e6f72672f6d656d6465762f73696c7665727374726970652d74656d706c617465686f6f6b732f646f776e6c6f6164733f666f726d61743d666c6174)](https://packagist.org/packages/memdev/silverstripe-templatehooks)[![Latest Unstable Version](https://camo.githubusercontent.com/e14ae8217f233ff221bfac85f3551791c4116669b0e6a00e1307e59cc21e7572/68747470733a2f2f706f7365722e707567782e6f72672f6d656d6465762f73696c7665727374726970652d74656d706c617465686f6f6b732f762f756e737461626c653f666f726d61743d666c6174)](https://packagist.org/packages/memdev/silverstripe-templatehooks)[![License](https://camo.githubusercontent.com/e02ee8a69d7d4b92d339a643284148ef4c4e51538684e227ae610a0ff81f4a02/68747470733a2f2f706f7365722e707567782e6f72672f6d656d6465762f73696c7665727374726970652d74656d706c617465686f6f6b732f6c6963656e73653f666f726d61743d666c6174)](https://packagist.org/packages/memdev/silverstripe-templatehooks)[![Build Status](https://camo.githubusercontent.com/92203093dbf9c18b1f05ca0e5d84376d2c62ab034629c32e4de6307806282198/68747470733a2f2f7472617669732d63692e6f72672f6d656d6465762f73696c7665727374726970652d74656d706c617465686f6f6b732e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/memdev/silverstripe-templatehooks)

Sometimes extending / overriding a template is not enough or would produce a lot of duplicate markup. Maybe you just want to inject some markup at a specific point in your template file. This is where template hooks come into play.

With template hooks, you can add named "injection points" everywhere in your SilverStripe template files and hook into them from within your Controllers or DataObjects.

Requirements
------------

[](#requirements)

- silverstripe/framework 3.1+

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

[](#installation)

```
$ composer require memdev/silverstripe-templatehooks
```

You'll need to do a flush by appending `?flush=1` to your site's URL.

Usage
-----

[](#usage)

To add a hook point to your template, simply call `$TemplateHook()`, providing a name for this hook as the first parameter:

```

        ²

                $MenuTitle.XML

            $TemplateHook('MainNavigation')

    $TemplateHook('AfterMainNavigation')

```

You can subscribe to this hook by calling `hookInto()` in your Controller or DataObject:

```
class Page_Controller extends ContentController implements TemplateHooks {

	/**
	 * Use this method to globally subscribe to template hooks.
	 * If you wish to subscribe to hooks in the current controller / object scope,
	 * call "hookInto()" from within any other method, e.g. the controllers init() method.
	 */
	public function initHooks()
	{
		$this->hookInto('MainNavigation', function($hook) {
			return SSViewer::execute_template('MyNavigationAppendix', array());
		});
	}

	public function init() {
		parent::init();

		$this->hookInto('AfterMainNavigation', array($this, 'AfterMainNavigationHook'));

		// OR

		$self = $this;
		$this->hookInto('AfterMainNavigation', function($hook) use ($self) {
		    return "You are currently reading page {$self->Title}";
		});
	}

	public function AfterMainNavigationHook($hook) {
	    return "You are currently reading page {$this->Title}";
	}
}
```

You can also pass parameters with the template hook:

```

            $TemplateHook('MainNavItem', $ID)
            $MenuTitle.XML

```

It will be available in your subscriber function:

```
$this->hookInto('MainNavItem', function($hook, $id) {
    $page = Page::get()->byID($id);
    // your code here
}
```

Documentation
-------------

[](#documentation)

TODO

Reporting Issues
----------------

[](#reporting-issues)

Please [create an issue](http://github.com/memdev/silverstripe-templatehooks/issues) for any bugs you've found, or features you're missing.

###  Health Score

28

—

LowBetter than 52% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity64

Established project with proven stability

 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.

###  Release Activity

Cadence

Every ~4 days

Total

2

Last Release

3721d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/92549961?v=4)[memdev.](/maintainers/memdev)[@memdev](https://github.com/memdev)

---

Top Contributors

[![manuelteuber](https://avatars.githubusercontent.com/u/655280?v=4)](https://github.com/manuelteuber "manuelteuber (8 commits)")

---

Tags

silverstripehookstemplatehookstemplate hooks

### Embed Badge

![Health badge](/badges/memdev-silverstripe-templatehooks/health.svg)

```
[![Health](https://phpackages.com/badges/memdev-silverstripe-templatehooks/health.svg)](https://phpackages.com/packages/memdev-silverstripe-templatehooks)
```

###  Alternatives

[silverstripe/login-forms

A collection of templates for the CMS login screens

191.4M30](/packages/silverstripe-login-forms)[silverstripe-themes/simple

The SilverStripe simple theme (default SilverStripe 3 theme)

411.3M8](/packages/silverstripe-themes-simple)[stevie-mayhew/silverstripe-svg

Basic SVG support for SilverStripe

22355.3k4](/packages/stevie-mayhew-silverstripe-svg)[symbiote/silverstripe-listingpage

A module that allows CMS users to create templated listing pages.

1012.9k3](/packages/symbiote-silverstripe-listingpage)[rywa/silverstripe-foundation-forms

Add ZURB Foundation framework forms compatibility to SilverStripe 3

126.4k](/packages/rywa-silverstripe-foundation-forms)[axllent/silverstripe-tiled-gridfield

Inline/tiled images in a Silverstripe GridField table

163.3k](/packages/axllent-silverstripe-tiled-gridfield)

PHPackages © 2026

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