Class LastInSequenceHandlebarsHelper

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

    @Component
    public class LastInSequenceHandlebarsHelper
    extends BaseHelper
    The {{lastInSequence}} handlebars helper is used to target the currently publishing content item when it's the last content item in a group of content items in the section using the same content type.

    In general this helper is used as a block level helper, but if used as an inline expression, it returns true for the last content item within a group of the current type and false for others.

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

    By default, this helper considers a single content element as a "sequence". If you only want to match in cases where this is the last of a number of content items using the same content type, the match-single attribute should be used.

    Usage

      {{#firstInSequence}}
       <ul>
      {{/firstInSequence}}
        <li>{{publish element="Name"}}</li>
      {{#lastInSequence}}
       </ul>
      {{/lastInSequence}}
     

    In the above example, an opening ul is output for the first content item in a sequence of content items in the section that all use the content type of the currently publishing content item and a closing ul is output for the last one. This allows for sequences of content items of the same type to be wrapped with specific code, in this case an unordered list.

    Attributes

    The lastInSequence handlebars helper can take a single attribute.

    • match-single - Whether or not the helper should match a single content item. If not set, this defaults to true
    See Also:
    FirstHandlebarsHelper, LastHandlebarsHelper, FirstInSequenceHandlebarsHelper
    • Constructor Detail

      • LastInSequenceHandlebarsHelper

        @Autowired
        public LastInSequenceHandlebarsHelper​(IContentAPI contentApi,
                                              IHandlebarsAPI handlebarsApi)
    • 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.