Class EqHandlebarsHelper

  • All Implemented Interfaces:
    com.github.jknack.handlebars.Helper<Object>

    @Component
    public class EqHandlebarsHelper
    extends BaseHelper
    The {{eq ...}} handlebars helper extends the core eq that is provided as part of handlebars.java.

    This extended version checks if two values are equal.

    Usage

    The {{eq ...}} helper takes the following format.

            {{[#]eq [value1] [value2]}}
     

    Attributes

    • #: should be added before the helper name when using it as a block expression, otherwise will be considered as standard expression.
    • value1: string/numeric value or handlebars expression. For example "first value" or (nav id="2").
    • value2: string/numeric value or handlebars expression. For example "second value" or (nav id="3").

    Examples

    Block expression

            {{#eq value1 value2}}
                    <p>To be displayed when they are equal</p>
            {{else}}
                    <p>To be displayed when they are not equal</p>
            {{/eq}}
     

    This would return <p>To be displayed when they are equal</p> in case the values are equal, otherwise <p>To be displayed when they are not equal</p>.

    Standard expression

            {{#or (eq value1 value2) (eq value1 value3)}}
                    <p>To be displayed when they are equal</p>
            {{/or}}
     

    This would return <p>To be displayed when they are equal</p> in case any of the two eq expressions are true (their values are equal).

    • Constructor Detail

      • EqHandlebarsHelper

        public EqHandlebarsHelper()
    • Method Detail

      • apply

        public Object apply​(Object value1,
                            com.github.jknack.handlebars.Options options)
                     throws IOException
        Description copied from class: BaseHelper
        The apply 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 interface com.github.jknack.handlebars.Helper<Object>
        Specified by:
        apply in class BaseHelper
        Parameters:
        value1 - The currently executing context.
        options - The options.
        Returns:
        The generated output.
        Throws:
        IOException - If processing of the expressions fails.