Class FirstHandlebarsHelper

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

    @Component
    public class FirstHandlebarsHelper
    extends BaseHelper
    The {{first}} handlebars helper is used to process the first content item in a section in a different way to the rest of the content items in the section.

    In general this helper is used as a block level helper, but if used as an inline expression, it returns true for the first content item and false for others.

    If there is no currently publishing content item, this helper returns false.

    Usage

      {{#first}}
       <ul>
      {{/first}}
        <li>{{publish element="Name"}}</li>
      {{#last}}
       </ul>
      {{/last}}
     

    In the above example, an opening ul is output for the first content item in the section and a closing ul is output for the last content item. This allows for all content items to be wrapped with specific code, in this case an unordered list.

    See Also:
    LastHandlebarsHelper, FirstOfTypeHandlebarsHelper, LastOfTypeHandlebarsHelper
    • Constructor Detail

    • Method Detail

      • apply

        public Object apply​(Object context,
                            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:
        context - The currently executing context.
        options - The options.
        Returns:
        The generated output.
        Throws:
        IOException - If processing of the expressions fails.