public class EachHelper extends BasicSectionHelper
{{#each items}}
{{name}}
{{/each}}
It's possible to apply a function to each element. The function must be an
instance of Function or a string referencing a built-in function. If
the result does not equal to SKIP_RESULT it's used instead
of the original element. If the result equals to
SKIP_RESULT the element is skipped. This might be useful
to filter out unnecessary elements or to wrap/transform elements.
{{#each items apply=myFunction}}
{{name}}
{{/each}}
There are some built-in functions that can be specified using string literals:
Checker.isFalsy(Object))
{{#each items apply="skipUnless:active"}}
Inactive items are skipped
{{/each}}
{{#each items apply="skipIf:name.isEmpty"}}
Items with null or empty names are skipped
{{/each}}
{{#each items apply="map:name"}}
Iterate over names
{{/each}}
It's also possible to supply an alias to access the value of the current iteration:
{{#each items as='item'}}{{item.name}}{{/each}}
This helper could be used to iterate over multiple objects:
{{! First iterate over list1 and then iterate over list2}}
{{#each list1 list2}}
{{name}}
{{/each}}
Function| Modifier and Type | Field and Description |
|---|---|
static String |
SKIP_RESULT |
SECTION_TYPESHELPER_TAG_TYPESconfiguration| Constructor and Description |
|---|
EachHelper() |
| Modifier and Type | Method and Description |
|---|---|
void |
execute(Options options)
Execute the helper.
|
protected Set<String> |
getSupportedHashKeys() |
void |
init()
Can be overridden so that there's no need to call
super.init(Configuration). |
protected int |
numberOfRequiredParameters() |
allowedTagTypesgetRequiredHashKeys, numberOfRequiredHashEntries, validateappend, convertAndAppend, convertValue, isSection, isUnescapeVariable, isVariablecheckNotInitialized, initclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitgetConfigurationKeys, initpublic static final String SKIP_RESULT
public void init()
AbstractConfigurationAwaresuper.init(Configuration).init in class AbstractHelperpublic void execute(Options options)
Helperprotected int numberOfRequiredParameters()
numberOfRequiredParameters in class BasicHelperprotected Set<String> getSupportedHashKeys()
getSupportedHashKeys in class BasicHelper* to
allow any hash keysCopyright © 2017. All rights reserved.