Chapter 22. Template helpers

Table of Contents

Introduction
Writing template helpers
A simple template helper
Using custom stylesheets and JavaScripts

Introduction

A template helper is a class that encapsulates one or more pieces of dynamic template code. Template helper classes can be provided by custom modules, or they can be written standalone. The purpose of a custom template helper is to add functionality to your page templates when the DMGenericTemplateHelper classes do not meet your needs.

[Note]Note

Custom helpers were known as "extensions" in dmBridge 1.x. They have been renamed because version 2 supports several other types of "extensions," of which custom helpers are only one kind.

Advantages of template helpers include:

  • They are isolated from the rest of the dmBridge code, making them easy to preserve across upgrades.

  • They are isolated from the rest of your template code, allowing them to be shared across template sets, and among other users.

  • They are consolidated and organized, making customizations easy to find.

  • They respect the standard dmBridge programming interfaces.

  • They prevent unexpected side effects from propagating to unexpected places.

  • They are unit-testable.

  • They hook into dmBridge's script and stylesheet management system, preventing duplicate scripts and stylesheets from being inserted into the page.

Using template helpers does not require PHP proficiency, but writing them does.