Custom expanders are much less common than custom formatters, but their API is simpler, so we will cover them first.

Each expander is implemented as a static method, where the name of the expander is the name of the method. The method takes one string argument (the input text) and returns a string value (the expanded text).

EachScape provides a default “text” expander that simply returns the text unchanged, allowing formatters to be applied to literal strings. The following examples show how the same functionality could be implemented as a custom expander named “identity”.

For iOS, you must implement a category on the class ESTemplateExpander.

#import "ESTemplateExpander.h"

@implementation ESTemplateExpander (ESCustomHooks)

+ (NSString *)identity:(NSString *)text {
  return text;
}

@end

For Android, you must implement an inner class TemplateExpander within the class ESCustomHooks.

package com.eachscape.models.other.scripts;

public final class ESCustomHooks
{
  public final static class TemplateExpander
  {
    public static final String identity(String text) {
      return text;
  }
}

Note that in both cases, the name of the static method is the name of the expander. With this custom expander implemented, this template:

[[identity:fred]]

would return the string “fred”.