TemplateProcessor

public class TemplateProcessor

Utility to replace double brace wrapped text with values extracted from a DataObject.

  • Processes the input text looking for all occurrences of double brace wrapped text: {{ }}

    The format of text inside the braces can be as follows:

    • a valid json path style string: e.g. {{container.key}}
    • a valid json path style string with an optional fallback: e.g. {{container.key || fallback}}
      • in the event that container.key is not available in the context object, the fallback will be used

    All occurrences of the templating {{ }} will be replaced with either the value from the context object according to the json path specified, or the fallback string if provided, else a blank string ""

    Declaration

    Swift

    public class func process(text: String, context: DataObject) -> String

    Parameters

    text

    the String to process for {{ }} substitution block

    context

    the DataObject to extract values from

    Return Value

    A new string with all substitution blocks replaced