Adding A Bright Template to a WordPress Page or Post

Bright uses a combination of WordPress shortcodes and the Bright Templating System to embed a course or courses onto the WordPress site. These shortcodes can be placed anywhere a regular WordPress shortcode can go, such as in

  • posts
  • pages
  • widgets
  • from any page template or theme file using the do_shortcode function.

Bright includes a little widget on the page and post editor in wordpress [in text mode] that can generate a Bright shortcode for you.

2016-10-11_1001

Select The Template Type

Templates are really just HTML blocks with some contextual references to courses or registrations in them. So when using the template, check the template documentation to determine its type:

  • course
  • courselist
  • generic

Once you know your template type: click ‘Select a Course’:

sac

Then pick the option that matches your template type:

2016-10-11_1013

Select your template

Now click “select a template”

2016-10-11_1018

And pick the template you would like to embed:

2016-10-11_1019

Choose Your Embedding Model

2016-10-11_1022

Once you’ve generated a template, you can add extra attributes to the shortcode as directed by the documentation for your template. Template documentation can be found on this site by searching for the template name, and looking for a document with the format “Template: {template-name}”.

Follow the directions above to generate a shortcode for an existing template, and select “embed template contents” in the final step.

At this point in your post, you will have something like this:

[bright type=”course|courselist|generic”] <> [/bright]

You can edit the template code here, or create a new template with a unique name that you can use other places on your website. Do this by using the following code block in your functions.php or within a plugin file:

$bright = \Bright\Wordpress::getInstance();
$bright->addTemplate('my-template-name',<<<EOF
<<The template code for your selected template>>
EOF;

Once you’ve saved your PHP file, programmatic errors notwithstanding your new template ‘my-template-name’ will now be available to any bright shortcode on your site.

Specifying the Template Type

All Bright shortcodes conform to the following format:

[bright type=”template-type” {extra attributes}]

where template type is one of:

  • course
  • courselist
  • generic

Note if you omit the ‘type=’ attribute, it will default to “type=course”. This is not recommended and may be removed at a future date.

Embedding a Single Course

Bright Shortcodes that embed a single course must reference the course GUID in one of two ways.

The most common model is via the shortcode itself:

[bright type=”course” course=”my-course-guid” {extra attributes]]

You may also omit the course=”” section from the Bright short code and instead use it via the HTTP query parameters:

http://mypage?bright_course_id=

Embedding a List of Courses

Templates that iterate over a list of courses [typically applying conditional logic to the course or associated registration] must specify their type as “courselist”.

[bright type=”courselist” {extra-attributes}]

Generic Templates

A generic template is special kind of customized template that doesn’t use the builtin context models for course or courselist templates.

[bright type=”generic” {extra-attributes}]

Specifying the Template Text Via Shortcode Attributes

You can specify a template that is known to Bright via a shortcode attribute:

[bright type=”course|courselist|generic” template=”{template-name}”/]

The template itself is any text that has been registered to the Bright plugin via the following call in PHP:

$bright = \Bright\Wordpress::getInstance();
$bright->addTemplate('my-template',<<<EOF
This is my Template text!
The course title is {{title}}.
EOF;

A great way to get started with writing templates is to grab the text of an existing template, like ‘classic’.

Using An Inline Template

An inline template doesn’t use the template= shortcode attribute. Rather the template text is simply places within the opening and closing tags of the shortcode:

[bright type=”course|courselist|generic” template=”{template-name}”] This is my Template text! The course title is {{title}}. /]