Class IfSetHandlebarsHelper
- java.lang.Object
-
- com.terminalfour.publish.handlebars.helper.BaseHelper
-
- com.terminalfour.publish.handlebars.helper.content.element.IfSetHandlebarsHelper
-
- All Implemented Interfaces:
com.github.jknack.handlebars.Helper<Object>
@Component public class IfSetHandlebarsHelper extends BaseHelper
The {{ifSet ...}} handlebars helper allows you to apply logic based on whether a Content Element has a value or not.NB: Please see #RDSM-33728 - ifSet differs to "selective" in how blank values are treated.
Usage
This helper can be used as either a standard expression, in which case it returns a boolean true or false or as a block level expression, in which case it processes either block depending on whether the Content element has a value set or not.
Attributes
When used as either a standard or block expression, there is only a single attribute available.
- element - The Content element to check.
Standard expression
The standard use case for this expression is generally to allow for the expression to be chained.
Example
{{#and (ifSet element="URL") (ifSet element="Text")}} <a href="{{publish element="URL"}}">{{publish element="Text"}}</a> {{/and}}
In the above example, processing of the block only occurs if both the URL and Text Content Elements have values set.
Block Expression
The block use case for the ifSet expression is the more common usage scenario, where a block is processed if a single Content Element has a value set.
Example
{{#ifSet element="Element Name"}} <div>{{publish element="Element Name"}}</div> {{/ifSet}}
In this example, processing of the block only occurs if the Element Name Content Element has a value set.
-
-
Constructor Summary
Constructors Constructor Description IfSetHandlebarsHelper(IElementAPI elementApi, IHandlebarsAPI handlebarsApi)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Object
apply(Object context, com.github.jknack.handlebars.Options options)
Theapply
method is the main entry point for handlebars.java helpers.
-
-
-
Constructor Detail
-
IfSetHandlebarsHelper
@Autowired public IfSetHandlebarsHelper(IElementAPI elementApi, IHandlebarsAPI handlebarsApi)
-
-
Method Detail
-
apply
public Object apply(Object context, com.github.jknack.handlebars.Options options) throws IOException
Description copied from class:BaseHelper
Theapply
method is the main entry point for handlebars.java helpers.It is called internally by the handlebars.java engine when a matching handlebars.java expression is encountered.
- Specified by:
apply
in interfacecom.github.jknack.handlebars.Helper<Object>
- Specified by:
apply
in classBaseHelper
- Parameters:
context
- The currently executing context.options
- The options.- Returns:
- The generated output.
- Throws:
IOException
- If processing of the expressions fails.
-
-