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

ActiveSilverstripe-module

sunnysideup/reflection-templates
================================

Provides introspection of SilverStripe templates with an API for getting variables and blocks, much like the PHP ReflectionClass.

1.0.0(6y ago)0199BSD-3-ClausePHP

Since Nov 24Pushed 6y ago1 watchersCompare

[ Source](https://github.com/sunnysideup/silverstripe-reflection-templates)[ Packagist](https://packagist.org/packages/sunnysideup/reflection-templates)[ RSS](/packages/sunnysideup-reflection-templates/feed)WikiDiscussions master Synced 4w ago

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

Reflection Templates for SilverStripe
=====================================

[](#reflection-templates-for-silverstripe)

A set of classes that introspect SilverStripe templates, getting metadata about variables and blocks, much like PHP's ReflectionClass.

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

[](#installation)

`composer require unclecheese/reflection-templates:dev-master`

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

[](#requirements)

SilverStripe 3.1 or higher

Usage
-----

[](#usage)

Given a template such as this:

```

  $Headline
  $Image.CroppedImage(200,200)
  $Category.Title
  it's featured

    $Title ($Date.Nice)

      This article, called $ArticleTitle is related to $Up.Title published

    $Description

```

We can introspect it using a `ReflectionTemplate` like so:

```
 $reflector = ReflectionTemplate::create();
 $reflector->process(file_get_contents('/path/to/template.ss'));

 foreach($reflector->getTopLevelVars() as $varName => $type) {
 	echo "The template variable $varName is likely a $type\n";
 }

 foreach($reflector->getTopLevelBlocks() as $block) {
 	 echo "There is a block at the top level named {$block->getName()}\n";
 	 echo $block->isLoop() ? "\tThis block is a loop\n" : "\tThis block is a with\n";
 	 foreach($block->getVars() as $var => $type) {
 		echo "\tThe top level block {$block->getName()} contains a variable named $var that is likely a $type\n";
 	 }
 	 foreach($block->getChildren() as $child) {
 		echo "\tThere is a child block named {$child->getName()}. It has the following vars:\n";
 		foreach($child->getVars() as $v => $t) {
 			echo "\t\tThe nested block {$child->getName()} contains a variable named $v that is likely a $t\n";
 		}
 	 }
 }

```

This produces the following result:

```
The template variable Headline is likely a Text
The template variable Image is likely a Image
The template variable Category is likely a has_one
The template variable Featured is likely a Boolean
There is a block at the top level named Items
	This block is a loop
	The top level block Items contains a variable named Title that is likely a Text
	The top level block Items contains a variable named Date that is likely a Date
	There is a child block named Articles. It has the following vars:
		The nested block Articles contains a variable named ArticleTitle that is likely a Text
		The nested block Articles contains a variable named Published that is likely a Boolean
There is a block at the top level named FeaturedProduct
	This block is a with
	The top level block FeaturedProduct contains a variable named Description that is likely a Text

```

Contextual template reflection
------------------------------

[](#contextual-template-reflection)

You can use one of the two context-sensitive reflectors to surface only variables and blocks that are user-defined.

- `SiteTreeReflectionTemplate` comes loaded with context about methods and variables that are made available to all `SiteTree` and `ContentController` contexts, and filters out things like `$Menu`, `$SiteConfig`, etc.
- `EmailReflectionTemplate` works similarly, filtering out variables like `To`, `Subject`, etc., that are made available to all emails.

For all that is good and holy in this world, WHY?!
--------------------------------------------------

[](#for-all-that-is-good-and-holy-in-this-world-why)

I found myself in need of it recently, and I had all this code kicking around from the old [SilverSmith](http://github.com/unclecheese/SilverSmith) project, and decided its best not left to sit and rot into oblivion. Hopefully someone else can make use of this insanity.

Todo
----

[](#todo)

Add a task that will generate PHP classes given a template

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity57

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.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

2357d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/167154?v=4)[Sunny Side Up](/maintainers/sunnysideup)[@sunnysideup](https://github.com/sunnysideup)

---

Top Contributors

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

---

Tags

silverstripetemplates

### Embed Badge

![Health badge](/badges/sunnysideup-reflection-templates/health.svg)

```
[![Health](https://phpackages.com/badges/sunnysideup-reflection-templates/health.svg)](https://phpackages.com/packages/sunnysideup-reflection-templates)
```

###  Alternatives

[silverstripe/cms

The SilverStripe Content Management System

5163.4M1.3k](/packages/silverstripe-cms)[silverstripe/admin

SilverStripe admin interface

262.6M325](/packages/silverstripe-admin)[silverstripe/silverstripe-omnipay

SilverStripe Omnipay Payment Module

38106.0k15](/packages/silverstripe-silverstripe-omnipay)[silverleague/ideannotator

Generate PHP DocBlock annotations for DataObject and DataExtension databasefields and relation methods

4768.0k43](/packages/silverleague-ideannotator)[feejin/silverstripe-securitytemplates

Custom security templates to mirror CMS

128.1k1](/packages/feejin-silverstripe-securitytemplates)[symbiote/silverstripe-usertemplates

Provides user-definable templates within the CMS that can be applied to content trees. Allows specification of Layout and main templates, as well as associating css + js files

1414.5k1](/packages/symbiote-silverstripe-usertemplates)

PHPackages © 2026

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