Teacher

How do I use replacement variables?

Follow
Ryan Richins
  • Agilix team member
  • Updated:
    info_outline
    Created:

Easily personalize your students' experience with variables.

What are replacement variables?

Replacement variables provide another way to simply and uniquely personalize each user's learning experience. Place variable codes in your content, and Buzz automatically replaces the variables with dynamic values drawn from user, course, and/or domain information.

Example

Buzz allows you to use variables in the content that appears on an activity folder's landing page. This example uses the $USERFIRST$ code, allowing the teacher to address each student by first name, and the $COURSENAME$ code, which means that they can change the name of the course without having to edit this folder's landing content.

What are replacement variables?

Now, this is what Wanda sees when she opens that activity folder.

Where can I use replacement variables?

Currently, you can use variables in the following locations:

Predefined domain-wide replacement variables

This table outlines the predefined variable codes that are available in all Buzz domains. Simply set the variable code between dollar signs ($) to activate the variable, like this: $VARIABLECODE$.

Name Value
DOMAINID The ID of the current user's domain
DOMAINNAME The current user's domain name
USERID The current user's ID. This ID is unique only within the Userspace; i.e., the USERSPACE/USERID value uniquely identifies a user in Buzz
USERNAME The current user's username. This name is unique only within the userspace.
USERSPACE The current user's userspace. The USERSPACE/USERNAME or USERSPACE/USERID combination uniquely identifies a user.
USER The current user's full display name
USERDISPLAY Same as USER
USERFIRST The current user's first name
USERLAST The current user's last name
USERREFERENCE The current user's external ID
ENROLLMENTID The current user's enrollment ID for the content they are viewing
ENROLLMENTFIRST First name of the current enrollment user
ENROLLMENTLAST Last name of the current enrollment user
ENROLLMENTREFERENCE The external ID of the current enrollment
ENROLLMENTUSER Full name (first and last name) of the current enrollment user
ENROLLMENTUSERNAME Username of the current enrollment user
ENROLLMENTUSERREFERENCE External ID of the current enrollment user
COURSEID The ID of the course the current user is viewing
COURSENAME The name of the course the current user is viewing
COURSEREFERENCE The external ID of the course the current user is viewing
ITEMID The ID of the item that the current user is viewing
ITEMNAME The item's title that the current user is viewing

How do I create my own replacement variables?

You can also create replacement variables for your own course:

  1. Open Course settings from the Editor toolbar.
  2. Click Add variable under Variables in the General tab.
    • Provide the variable Name, which is the variable code that will be replaced (e.g., SECTIONNUMBER).
    • Provide the variable Value, which is the value you want the code to be replaced by (e.g., Section 5).
  3. Save.
How do I create my own replacement variables?

Once you've created a course-specific replacement variable, you use it by placing it between dollar signs ($) just like you do with the other variable codes (e.g., $SECTIONNUMBER$).

Comments (9)

Sort by
Jill Zupetz

I really like this feature, but one thing I would like to see is the ability for these to be used on a course landing page. Thanks!

0 Comment actions Permalink
Aileen Sweeney

I have created a variable at a sub-domain level using the edit xml option.

It contains a URL to be used in that sub domain.

These samples are using fake data.

<variables>
    <variable name="snaphost">www.snaphost1.org/</variable>
  </variables>

This variable is then used in a course activity as part of the Website URL to replace a portion of the URL depending upon the logged in user's sub-domain's variable setting.

Example: Content website entered in the Course Activity is

https://$www.somesite-a.com$search/query/id:l360_67963

A set of Post parameters are used to pass authentication values.

POST Name     POST Value

USERNAME     $USERNAME$

Can I have a user enrolled and logged into sub domain A (which has the $snaphost$ value set to www.somesite-a.com) take a course in sub domain B (which has the $snaphost$ value set to www.somesite-b.com) work so that it replaces the $snaphost$ value with that of the the logged-in user's home sub-domain $snaphost? value. When I set the $snaphost$ at the subdomain's Admin screen, it propagates down to the course that uses the variable just fine.

 

 

0 Comment actions Permalink
Annette Walaszek

I agree this is a great feature. It would also be nice to be able to add the replacement variables to feedback templates.

 

0 Comment actions Permalink
Aileen Sweeney

I would like to be able to use the Username replacement variable at the sub-domain level so that I can use it in external URLS.

USERNAME is not listed as one of the replacement variables allowed.

I can use it at a course level by adding a Post Parameter and Value to an Activity 

and adding it as a Course Variable.

USERNAME $USERNAME$

 webmax.oneida-boces.org/index.php/snap/login/sso_search_refer_sm/search/username/$USERNAME$/query

I even included it in a domain landing page and it does not work.

Is there a way to get the Username variable to work at the sub-domain level for admins?

Replacement variables for custom Main Menu entries
Custom Main Menu URLs allow for dynamic replacement variables that automatically replace a variable code (options listed below) with a desired value drawn from user, course, and/or domain information.

Use any of the following replacement variables by enclosing them with double curly brackets (e.g., {{TOKEN}}, {{USERID}}, {{ADMINDOMAINID}}):

TOKEN: The xLi authentication token for the currently logged in user. When using this variable, the URL must be secure, starting with https.
USERID: The ID for the currently logged in user.
USERDOMAINID: The domain ID for the currently logged in user.
USERSPACE: The userspace for the customization domain, or the domain userspace visible in the top level URL.
ENROLLMENTID: The ID of the currently selected enrollment.
COURSEID: The ID of the course associated with the currently selected enrollment.
ADMINDOMAINID: The currently selected domain ID in the admin app.
QUERY-<param>: The value of the top page's query parameter with the case-sensitive name of <param>. The application only replaces this variable if external is not set to true.

0 Comment actions Permalink
Scott Taylor

Hello Aileen,

The username variable isn't currently supported as a replacement variable at the domain level. We'll pass along your request for consideration in discussions on future updates to the list of domain replacement variables.

0 Comment actions Permalink
Shaun Creighton

Is it possible to use replacement variables within content templates? We're exploring the creation of templates to make it easy to build content up quickly, and I tried putting some of these variables into the template, but when I preview the pages created from the templates, it just displays the code for the variable instead of the value of the variable.

I tried creating activities that were not tied to the template and using variables in those, and they displayed fine. Is there something about the templates that "breaks" the use of variables?

0 Comment actions Permalink
Brad Marshall
  • Agilix team member

Hey Shaun, I think you may be reading my mind.

I will be publishing a video (soon) showing some tips about Content Templates. Variables do not natively get replaced in a course activity that is using a course resource. These course resources are loaded in an `iframe` in Buzz and can contain JavaScript (JS) or other code that we do not want to crawl against. A main benefit of these course resources is that they stay true to how they were developed and designed without Buzz interfering. Well, replacing a variable could be some interference.

That said, one of the tips I will be sharing is how you can use variables in your Content Template. However, it requires that the developer chooses how and when they are used.

Let me give you some ideas of how I accomplished this, all using pure JS and Buzz-supported features.

1. Identify which variables you want.

Let's say we want to use the ITEMNAME and COURSEID variables.

2. Pass the variable to the course resource via "URL parameters".

Before flagging the activity as a Content Template, under the Activity tab, paste

itemname=$ITEMNAME$&courseid=$COURSEID$

into the "URL parameters" field. What this will do is pass the variable into the query parameters for the iframe. Still with me?

3. Add JS to your Content Template to retrieve those variables.

There are many different ways you can accomplish this. The easiest approach I have implemented is by using the following code.

var urlParams = new URLSearchParams(window.location.search);
var item_name = urlParams.get('itemname');
var course_id = urlParams.get('courseid');

Specifically, what this is doing is creating a JS variable named `urlParams` that allows for a key to be passed in to identify the value for that key in the window's query parameters. The following two JS variables, `item_name` and `course_id`, directly correlate to the course variables you passed and are available for use.

4. Add JS to your Content Template to use those variables.

Now, its' time to use the variables in your content. For simplicity, let's say that the only thing we want to do is inject the ITEMNAME course variable into an element on the page. Let's say we want to put the ITEMNAME into an element that has the HTML ID of `content_template_title`. I'll use this JS to do so.

document.getElementById('content_template_title').innerHTML = item_name;

What that JS is doing is finding the HTML element with the ID of `content_template_title` [document.getElementById('content_template_title')] and then replacing the text [.innerHTML] with the JS variable `item_name`.

Hopefully you followed along. Let me know if you have any questions. I hope to have the video, tips, and examples published soon.

1 Comment actions Permalink
Shaun Creighton

That worked beautifully ... I really appreciate the quick response (and can't wait to see the video you're putting together). Thanks for your help, Brad!

0 Comment actions Permalink
Brad Marshall
  • Agilix team member

We have posted a new new Buzz in Practice article, Use Content Templates to improve branding, functionality, and authoring, to demonstrate how Content Templates can be used.

0 Comment actions Permalink
Please sign in to leave a comment.