Welcome, Guest Login

Support Center

Create Your Own Formatter With Native Code

Last Updated: Oct 14, 2015 05:37PM EDT

Each formatter is implemented as a static method, where the name of the formatter is the name of the method. The method takes two string arguments (the input text and an optional string argument) and returns a string value (the formatted text).

EachScape provides a “left” formatter that returns a left-anchored substring of the input string. This example shows you how to create a formatter called "leftmost" that does the same thing.

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

#import "ESTemplateFormatter.h"

@implementation ESTemplateFormatter (ESCustomHooks)

+ (NSString *)leftmost:(NSString *)text args:(NSString *)args {
  int count = [args intValue];
  int len = [text length];
  if (count > len) {
    count = len;
  return [text substringToIndex:count];


Paste the code shown above in the ios Hooks field of the iOS tab of the App Edit page, shown below. Note that this field is disabled if you do not have permission to edit it.

iOS Hooks Example

For Android, you must implement an inner class TemplateFormatter within the class ESCustomHooks. You need to insert this code in the Android Hooks field of the Android tab of the App Edit page. Note that this field is disabled if you do not have permission to edit it.

package com.eachscape.models.other.scripts;

public final class ESCustomHooks
  public final static class TemplateFormatter
    public static final String leftmost(String text, String args) {
      int count = 0;
      int len = text.length();
      try { count = Integer.parseInt(args); }
      catch (Exception e) {}
      if (count > len) {
        count = len;
      return text.substring(0, count);

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

[[text:fred:leftmost 2]]

would return the string “fr”.

Help us improve! Rate this article:

Yes I found this article helpful

Ask a Question   

seconds ago
a minute ago
minutes ago
an hour ago
hours ago
a day ago
days ago
Invalid characters found