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]; } @end
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.
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”.