Handlebars in Templates

Firebird can produce highly customisable emails, document reports and online programme pages using the data collected within your project.

Firebird uses Handlebars for precise control over which data is displayed and how it is formatted.

Handlebars allows simple merge fields to be displayed, allows fields to be pulled out of nested data structures and to provide conditional logic to control what data is displayed.

This article outlines the different handlebars codes that can be used along with some examples.

Merge fields

To display data pulled out of your project, insert a merge field expression using the following format:

{{ObjectName.FieldName}}

Examples

The first name of the submitter of the submissions :

{{Submitter.FirstName}}

The date stored in the Submission Deadline field in the Project Settings:

{{Project.SubmissionDeadline}}}

The unique reference number of a submission:

{{Submission.ReferenceNumber}}

Each

If your data contains more than one item of the same type e.g. Multiple submissions for a single submitter, then you can look through the records by using a loop using the each keyword:

{{#each ObjectNames}} ....  {{each}}

There are two parts to the each expression, the {{#each}} and the {{/each}}. Between these two parts, the context is changed to the object that is being looped through.

Examples

Loop through each of the submitter's submissions and display the reference number and title. Inside the each loop, the context is that of a Submission and so the ObjectName is not required in the merge field:

{{#each Submitter.Submissions}}
   {{ReferenceNumber}} {{Title}}
{{/each}}

Loop through each of the reviewer's reviews and display the reference number of the associated submission:

{{#each Reviewer.Reviews}}
{{Submission.ReferenceNumber}}
{{/each}}

If

Sometimes, data should only be shown under certain conditions.  The if expression allows the template to check is something is available before displaying contents.

{{#if ObjectName.FieldName}} .... {{/if}}

There are two parts to the if expression, the {{#if}} and the {{/if}}.  The content between these two parts is only displayed if the if item is available or set to true.

Examples

Only display the "You only have one submission text" text if the submitter has a single submission

If the reviewer has more than one review then display the number of reviews

{{#if Submitter.HasSingleSubmission}}
    You only have one submission
{{/if}}
{{#if Reviewer.HasMultipleReviews}}
    You have {{Reviewer.Reviews.Count}} reviews
{{/each}}

IfEqual

Sometimes the value of a field needs to be the same as a specific value or another field's value

{{#ifEqual ObjectName.FieldName Value}} .... {{/ifEqual}}

{{#ifEqual ObjectName.FieldName OtherObject.OtherField}} .... {{/ifEqual}}

There are two parts to the ifEqual expression, the {{#ifEqual}} and the {{/ifEqual}}.  The content between these two parts is only displayed if the ifEqual expression is true.

Examples

Only display the "You will be first" text if the submitter's first initial is equal to 'A'

{{#ifEqual Submitter.FirsInitial 'A'}}
  You will be first
{{/ifEqual}}

Only display the "This is a Paper Review" text if the review type has the name of 'PaperReview'

{{#ifEqual ReviewType.Name 'PaperReview'}}
    This is a Paper Review
{{/ifEqual}}

IfNotEqual

Sometimes the value of a field needs to be different to a specific value or another field's value

{{#ifNotEqual ObjectName.FieldName Value}} .... {{/ifNotEqual}}

{{#ifNotEqual ObjectName.FieldName OtherObject.OtherField}} .... {{/ifNotEqual}}

There are two parts to the ifNotEqual expression, the {{#ifNotEqual}} and the {{/ifNotEqual}}.  The content between these two parts is only displayed if the ifNotEqual expression is false.

Examples

Only display the "You will be first" text if the submitter's first initial is equal to 'A'

{{#ifNotEqual Submitter.FirsInitial 'A'}}
  You will not be first
{{/ifNotEqual}}

Only display the "This is a Paper Review" text if the review type has the name of 'PaperReview'

{{#ifNotEqual ReviewType.Name 'PaperReview'}}
    This is not a Paper Review
{{/ifNotEqual}}

Format

Sometimes field data needs to be formatted in a particular way.

{{format ObjectName.FieldName formatString}}

The format expression takes two parameters.  The first is the merge field for the data to be displayed.  The second is a string describing how to format that data.

Standard format strings are defined on the Microsoft website.

Dates and Times

Numbers

Examples

Display the reference number with exactly 4 digits:

{{format ReferenceNumber '0000'}} 

Format the end date for the project using 2 digits for the date, the long month name and four digits for the year e.g. 12 January 2016:

{{format Project.EndDate 'dd MMMM yyyy'}}

Contains

Sometimes content needs to be displayed if a collection of objects contains a certain value

{{#contains ObjectNames FieldName Value}} .... {{/contains}}

There are two parts to the contains expression, the {{#contains}} and the {{/contains}}. The content between these two parts is only displayed if the contains expression is true.

Examples

Only display the "SPECIAL PRODUCT" text if the customer's order items contains the product with id of 29

{{#contains Customer.OrderItems "ProductId" 29}}
   SPECIAL PRODUCT
{{/contains}}

Only display the "PRESENTER" text if the submission has an author that is flagged as "Presenter"

{{#contains Submission.Authors "Presenter" "True"}}
    PRESENTER
{{/contains}}

BoldBracketHtml

Sometimes part of a text has to be highlighted based on a condition.

{{#boldBracketHtml}} .... {{/boldBracketHtml}}

{{#boldBracketHtml condition}} .... {{/boldBracketHtml}}

There are two parts to the boldBracketHtml expression, the {{#boldBracketHtml}} and the {{/boldBracketHtml}}. The content between these two parts is always displayed. If the condition is missing or it is True, the content will put in the html tags and square brackets.

Examples

It will output the following html: <b>[This will be bracketed and bold]</b>

{{#boldBracketHtml}}
  This will be bracketed and bold
{{/boldBracketHtml}}

It will output the following html if condition is True: <b>[This might be bracketed and bold]</b> Or if condition is False: This might be bracketed and bold

{{#boldBracketHtml condition}}
  This might be bracketed and bold
{{/boldBracketHtml}}

Checks if Object.Property equals to OtherValue, and displays the content highlighted or not highlighted accordingly

{{#boldBracketHtml (equal Object.Property OtherValue)}}
  This will be bracketed only if Object.Property equals OtherValue
{{/boldBracketHtml}}

Icon

Add an Icon to your webpage.  

{{Icon 'IconName'}}

Note

Html Only. This helper will not work for content generated for Word or PDF output.

Example

Displays a Location icon

{{Icon 'Location'}}

StrikeHtml

Sometimes part of a text has to be striked based on a condition.

{{#strikeHtml}} .... {{/strikeHtml}}

{{#strikeHtml condition}} .... {{/strikeHtml}}

There are two parts to the strikeHtml expression, the {{#strikeHtml}} and the {{/strikeHtml}}. The content between these two parts is always displayed. If the condition is missing or it is True, the content will put in the html tags.

Examples

It will output the following html: <strike>This will be striked</strike>

{{#strikeHtml}}
  This will be striked
{{/strikeHtml}}

It will output the following html if condition is True: <strike>This might be striked</strike> Or if condition is False: This might be striked

{{#strikeHtml condition}}
  This might be striked
{{/strikeHtml}}

Checks if Object.Property equals to OtherValue, and displays the content striked or not striked accordingly

{{#strikeHtml (equal Object.Property OtherValue)}}
  This will be striked only if Object.Property equals OtherValue
{{/strikeHtml}}

GetValueOrDefault

Sometimes the underlying data structure is a lookup dictionary and we need a value for a given key

{{getValueOrDefault dictionary key}}

{{getValueOrDefault dictionary key default}}

Examples

It will output the value from the dictionary for the given key. If the key is not found it will not output anything.

{{getValueOrDefault dictionary key}}

It will output the value from the dictionary for the given key. If the key is not found it will output the default parameter.

{{getValueOrDefault dictionary key default}}

List

Sometimes a list needs to be displayed with the items separated

{{#list values separator}} .... {{/list}}

There are two parts to the list expression, the {{#list}} and the {{/list}}. Between these two parts, the context is changed to the object that is being looped through. Between each iteration, the separator will be placed, but not in front of the first or after the last item.

Examples

Loop through each of the reviewer's reviews and display the reference number of the associated submission separated by commas:

{{#list Reviewer.Reviews ', '}}
    {Submission.ReferenceNumber}}
{{/list}}

Equal

Sometimes the value of a field needs to be the same as a specific value or another field's value

{{Equal ObjectName.FieldName Value}}

{{Equal ObjectName.FieldName OtherObject.OtherField}}

This can be used as a parameter for other helpers which require a True/False value, see BoldBracketHtml for an example.

Example

Displays True if the submitter's first initial is equal to 'A' or False if it isn't

{{Equal Submitter.FirsInitial 'A'}}

PlainText

Sometimes you need to display the value of a field or complete block as plain text. 

{{plainText ObjectName.FieldName}}

{{#plainText}} .... {{/plainText}}

The plainText expression can be used in two ways, either for fields or for complete blocks as the example shown above. Please note, that when in templates for HTML documents this template should not be used.

Examples

This example will output the following: Html ⇔ plain

{{#plainText}}
  <p>Html &hArr; plain</p>
{{/plainText}}

This example will output the value of ObjectName.FieldName as plaintext, without the HTML formatting.

{{#plainText ObjectName.FieldName}}

Comments