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}}

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}}

Renders

"Heisenberg"

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}}
matched
{{else}}
did not match
{{/bCompare}}

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:

 http://[my-url]/invitation-report/?invitation_name=land50234base

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}}
{{attributes.invitation_name}}
{{else}}
{{#bGetQueryParameter 'invitation_name'}}{{/bGetQueryParameter}}
{{/if}}
</h3>

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

Example:

{{(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'); ->
<!-- custom.one makes this return true -->
<!-- in this example paths is an array -->
{{#bHasAnyAttribute (bFetch 'paths') custom}}
something
{{else}}
something else
{{/if}}
 {{#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"}}

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}}
  <tr>
    <td>{{title}}</td>
  <td>{{registration.complete}}, {{registration.success}}</td>
    <td>{{#courselist-launchbutton this}}{{/courselist-launchbutton}}</td>
  <td>{{#if_course_completed}}
<a href="/certificate?bright_course_id={{course_guid}}">Certificate</a>
{{/if_course_completed}}
  </td>
  </tr>
{{/if}}
{{/bSortCourses}}

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}}
{{/bSortCourses}}

For more information see https://help.aura-software.com/template-bright-course-table/

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

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

Renders

"Heisenberg"

You can bCompare two values using a passable operator:

For example, to check that a course has passed:

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

The default is a '=='

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

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 -->
{{else}}
{{#bGetDefaultValue attributes.not_registered_message 'You must be pre-registered to take this course.'}}{{/bGetDefaultValue}}
{{/if}}
{{else}}
<!-- show a launchbutton -->
{{/bCompare}}

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

{{courselist-launchbutton}}

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.",
 "email": "admin@aura-software.com",
 "avatar": "http://0.gravatar.com/avatar/f1715eb1efc1cb4ec494c95a7b5fa584?s=96&d=mm&r=g
}

When you are rendering a course, ala:

[bright type="course" ...]

Use

{{{launchbutton}}}    

To insert the course launch button.

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

{{courselist-launchbutton}}

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

Display current server date:

[bright type="generic"]
{{#rightnow}}{{/rightnow}}
[/bright]

As:

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