Class FileHandlebarsHelper

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

    @Component
    public class FileHandlebarsHelper
    extends BaseHelper
    The {{file ...}} handlebars helper is used to publish file based Content Elements.

    Usage

    {{file element="Content Element"}}

    The file handlebars expression is used to publish file based Content elements.

    It should be noted that the file handlebars expression can be used as either a standard or a block expression. For more information, see the examples below.

    Attributes

    • element - The alias of the (File) Content Element to target.

    Examples

    Standard expression

       <a href="{{file element="Content Element"}}">Download</a>
      

    In this usage scenario, the URL to the publish file is returned and can be embedded in a link.

    Block expression

       {{#file element="Content Element"}}
        <a href="{{path}}">{{publish element="Name"}} ({{numberFormat (filesize element="The File")}}bytes)</a>
       {{/else}}
        <p>Publishing of file failed.</p>
       {{/file}}
      

    In this usage scenario, the developer has more control over the published output.

    It makes it possible to output a specific message if the file cannot be published, and also provides the developer with more control over the published output when the file is successfully published, by providing a {{path}} variable that can be output within a fully customizable block of code.

    • Constructor Detail

    • Method Detail

      • apply

        public CharSequence 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.