Class FirstInSequenceHandlebarsHelper

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

    @Component
    public class FirstInSequenceHandlebarsHelper
    extends BaseHelper
    The {{firstInSequence}} handlebars helper is used to target the currently publishing content item when it's the first content item in a sequence 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 first content item within a sequence 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 first 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 firstInSequence 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, LastInSequenceHandlebarsHelper
    • Constructor Detail

      • FirstInSequenceHandlebarsHelper

        @Autowired
        public FirstInSequenceHandlebarsHelper​(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.