silverstripe/silverstripe-framework — pull request #2596 by camspiers (2013-10-23 23:50:42+00:00)
Title: Allow users to extend the SSTemplateParser by defining open & closed blocks

Please note, I am yet to write the unit tests. I will write them if people are intested in this approach to extend SSTemplateParser.

Currently the only way the extend SSTemplateParser is to define a class
extension of it and then tell the injector component to use your new
custom class. This new change allows a user to define new "open blocks"
and "closed blocks" for SSTemplateParser to use without needing to
recompile the real SSTemplateParser class.

The following example shows how the functionality can be used
to add a new <% minify %>…<% end_minify %> syntax to the template parser

In a config.yml file, define the new minify closed block to call the
static function "Minifier::minify"

```
Injector:
SSTemplateParser:
properties:
closedBlocks:
minify: "Minifier::minify"
```

Define a new class with the minify static method that returns the new
template code when regenerating templates:

```
class Minifier {
public static function minify(&$res) {
return << zz\Html\HTMLMinify::OPTIMIZATION_ADVANCED));
PHP;
}
}
```