Bright Template Reference

The [bright] shortcode, aside from the shortcode attributes, can include template text, either inline or defined by a plugin.

This document covers functions available in the Handlebars model of double braces, \'{{}}\' within the template text.

Numerous built-in helper functions are available, documented here.

Allows you to assign a value in a namespace within the current context.

In the following example, we look to see whether the current user has a profile variable exported called \'bright_path\', and if it does, makes it operate like a shortcode attribute.

 {{#if user.meta.bright_path}}
   {{#bAssignToNamespace 'attributes' 'path' user.meta.bright_path}}{{/bAssignToNamespace}}

If you have a JSON string in a context variable, you can turn it into evaluated JSON.

For example, if in the current context

myjsonfield = 'this: {that: data}';

// then 
{{#bJsonEval this 'myjsonfield'}}{{/bJsonEval}} 
{{myjsonfield.this.that}}  <!-- renders as 'data' -->

Retrieves a value previously stored with {{bStore}}:

{{#bStore 'name' 'Heisenberg'}}{{/bStore}}
{{#bFetch 'name'}}{{/bFetch}}



When receiving a query parameter and referencing in a template, this helper is useful to decode URI encoding:

For example, this block fetch a certificate title from the query parameters

{{bGetDefaultValue attributes.certificate_title (bDecodeUri (bGetQueryParameter 'learning-path-title'))}}

Returns a default value in place of an unset template attribute, for example.

{{#bCompare (bGetDefaultValue attributes.success_criteria 'passed') registration.success}}
did not match

In this example, we are looking for a template argument called \'success_criteria\'. If it is set, we will use that in our comparison statement with the value in registration.success.

If not set, we use the default value of \'passed\'.

You extract query parameter arguments with this function:


In the template, try

{{#bGetQueryParameter 'invitation_name'}}{{/bGetQueryParameter}}

So as an example, for invitation reports we use the shortcode embedder, if not present, then we use the query parameter:

<h3>{{#if attributes.invitation_name}}
{{#bGetQueryParameter 'invitation_name'}}{{/bGetQueryParameter}}

Usage: You can use this to conditionally access an object by a different field name.


{{(bGetValueFromObject registration (bGetDefaultValue attributes.criteria_field 'success'))}}

Thus bGetDefaultValue evaluates the attributes field, and if \'criteria_field\' is selected, this is used to extract data from the registration object.

Otherwise, we will use the default of \'success\'.

This function takes as arguments a list of strings, and an object. If any of the strings is an attribute of the object render the passed in block. Otherwise render the inverse.

<!-- paths = Array('one','two','three'); ->
<!-- makes this return true -->
<!-- in this example paths is an array -->
{{#bHasAnyAttribute (bFetch 'paths') custom}}
something else
 {{#bI18n 'started'}}{{/bI18n}}

Represent a possibly internationalized string.

Converts a date that comes from the Bright API into something human readable.

It defaults to the US model, but can write out a European style [day,month,year] by setting model='EU'.

 {{bHumanizeDate registration.provider_completed_at model='EU'}}

To get a date in natural language, like "February 20, 2022" use 'natural' as an argument.

bSortCourses takes a context document that includes an array of course records, and sorts/iterates overthem, calling the interior block with each course as the context of the interior block.

This is the helper to use to iterate over a courselist [like in a Bright courselist template] and do something with each course.

{{#bSortCourses this courses sortBy=title}}
{{#if registration}}
  <td>{{registration.complete}}, {{registration.success}}</td>
    <td>{{#courselist-launchbutton this}}{{/courselist-launchbutton}}</td>
<a href=/certificate?bright_course_id={{course_guid}}>Certificate</a>

In the block below, the parent context is available in a context variable called \'context\':

{{#bSortCourses this courses sortBy=title reverse=true }}
{{#dump2 'context.realm' context.realm}}{{/dump2}}

For more information see

Stores a value that can be fetched later with a {{#bFetch \'value}}

{{#bStore 'name' 'Heisenberg'}}{{/bStore}}
{{#bFetch 'name'}}{{/bFetch}}



You can bCompare two values using a passable operator:

For example, to check that a course has passed:

{{#bCompare registration 'passed' operator='==='}}
<!-- do something ... -->

The default is a \'==\'

{{#bCompare registration 'passed'}} <!-- no operator required -->
<!-- do something ... -->

Note if you omit the \'operator\' part you will get an error like:

TypeError: Cannot read property \'operator\' of undefined

Error: Third argument to {{#bCompare}} must be in format operator='===' ; for instance

Operators Supported:

  • \'||\'
  • \'==\'
  • \'===\'
  • \'!=\'
  • \'!==\'
  • \'<\'
  • \'>\'
  • \'<=\'
  • \'>=\'
  • \'typeof\'

See also Javascript Guide for Comparison Operators.

Implement \'or\' functionality using bCompare

Here\'s a sample extracted from the Bright \'classic\' template:

{{#bCompare attributes.requires_registration attributes.require_registration operator='||'}}
{{#if registration}}
<!-- show a launchbutton -->
{{#bGetDefaultValue attributes.not_registered_message 'You must be pre-registered to take this course.'}}{{/bGetDefaultValue}}
<!-- show a launchbutton -->

This allows either requires_registration OR require_registration to be specified, in case of typos. If either returns true, bCompare returns true and shows the first 1/2 of the template.

Use this in a courselist, to add a launch button for the course you are currently rendering


This will generate a debugging statement in your template about the nested values associated with a context variable.

For example

{{{debug this}}}

Will show all values available in the template.

You can change the title of the generated document with:

{{{debug registration title='The most recent registration'}}}

Note: When dumping \'this\', the toplevel fields can be accessed withouth \'this\' prepended.

So instead of {{{this.user}}}, you can always use just {{{user}}}.

Dump provides a mechanism to view the data in the template context.

For example, to see the values of the attributes in the initial shortcode, use:

{{#dump attributes}}{{/dump}}

In your template.

So for an embedder code like:

[bright type=courselist template=results_matrix query=all_registrations suppress_header=true/]

You will get the following output in the page:

 type: courselist,
 template: results_matrix,
 query: all_registrations,
 suppress header: true,

The descendant of {{dump}}, gives some useful pointers on how to view nested data:

{{#dump2 'user' user}}{{/dump2}}

As passed to the templates the {{user}} variable are:

rendering {{#dump2 'user' user}}{{/dump2}}   ..... 
Top Level Names Are: meta, site_roles, email, avatar
Data Currently In Variable:
 meta: nested, use {{#dump2 'user.meta' user.meta}}{{/dump2}} to view.,
 site_roles: nested, use {{#dump2 'user.site_roles' user.site_roles}}{{/dump2}} to view.,

When you are rendering a course, ala:

[bright type=course ...]



To insert the course launch button.

Note if you are rendering a list of courses, please use


Please note the # of \'{\'s, they are important.

Display current server date:

[bright type=generic]


Wed Nov 11 2015 16:07:28 GMT-0700 (MST)