Class FileHandlebarsHelper
- java.lang.Object
-
- com.terminalfour.publish.handlebars.helper.BaseHelper
-
- com.terminalfour.publish.handlebars.helper.content.element.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 Summary
Constructors Constructor Description FileHandlebarsHelper(IElementAPI elementApi, IFileAPI fileApi, IJsonAPI jsonApi)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description CharSequence
apply(Object context, com.github.jknack.handlebars.Options options)
Theapply
method is the main entry point for handlebars.java helpers.
-
-
-
Constructor Detail
-
FileHandlebarsHelper
@Autowired public FileHandlebarsHelper(IElementAPI elementApi, IFileAPI fileApi, IJsonAPI jsonApi)
-
-
Method Detail
-
apply
public CharSequence apply(Object context, com.github.jknack.handlebars.Options options) throws IOException
Description copied from class:BaseHelper
Theapply
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 interfacecom.github.jknack.handlebars.Helper<Object>
- Specified by:
apply
in classBaseHelper
- Parameters:
context
- The currently executing context.options
- The options.- Returns:
- The generated output.
- Throws:
IOException
- If processing of the expressions fails.
-
-