- 10 Sep 2024
- 7 Minutes to read
- Print
Variably Display Instructions
- Updated on 10 Sep 2024
- 7 Minutes to read
- Print
Lab Instructions have a function to allow showing and hiding of lab instructions and lab instruction elements. This is done by setting a lab Variable and then using that lab variable in the lab instructions. This also works in conjunction with labs that use instructions stored in an external repository and displayed in the lab instructions using a Markdown Include - this allows the lab instructions to be displayed dynamically based on the variable in the lab instructions. Additionally, the variable can be selected with an API launch. This allows the lab to show specific content when the lab launches.
There are two requirements for enabling these features:
Setting Variables
The lab variable can be set multiple ways, but only needs to be set once in order to be used in lab instructions. The following methods can be used to set a lab variable:
Life Cycle Actions (LCA)
Set the lab variable in an LCA when the virtual machine or cloud environment are in the First Displayable or Resumed event.
On the lab profile, select Edit.
Go to the Life Cycle Actions tab.
Select Add Life Cycle Action.
Select the Action drop-down, then select Execute Script in Virtual Machine, Execute Script in Cloud Platform or Execute Script in Container.
Select the Event drop-down, then select First Displayable or Resumed. This will set the variable in lab when the VM or Cloud environment is first displayed to the user or resumed by the user.
Select the Command Type drop-down and select PowerShell.
For the Command, enter:
Set-LabVariable -Name variableName -Value variableValue
.Replace
variableName
with the name you wish to use for the variable.Replace
variableValue
with the value you wish to use for the variable.Configure the lab instructions to show items based on the variable, by configuring one of the options below.
For more information about LCAs, see our Life Cycle Action documentation.
Activity Based Assessments (ABA)
Set the lab variable in an ABA activity when the user selects the button for the activity in the lab instructions.
On the lab profile, select Edit Instructions.
Select the Activities menu (lightning bolt icon) at the top of the window.
Select New Automated Activity
Enter a name for the activity in the Name field.
Enter instructions in the Instructions field.
Configure the Correct Answer and Incorrect Answer feedback fields.
In the script section, select the Target drop-down and select VM or Cloud subscription you wish to target with the script.
In the Language drop-down menu, select PowerShell. Other options can be used, but this documentation uses PowerShell for demonstration.
For the script, enter:
Set-LabVariable -Name variableName -Value variableValue
.Replace
variableName
with the name you wish to use for the variable.Replace
variableValue
with the value you wish to use for the variable.Configure the lab instructions to show items based on the variable, by configuring one of the options below.
For more information about ABA, see our Activity Based Assessments documentation.
Textbox
Show lab instructions based on text a user enters into a textbox.
When a user enters text (variable value) into the textbox, any lab instructions or instruction elements that use that variable name will be shown. If a user enters text that does not correspond with a variable name, no lab instructions will be shown based on the user's input.
It is recommended to provide the variable values in the lab instructions, so that lab users can enter a variable value that corresponds to a variable name.
From the lab profile, select Edit Instructions.
Select the @lab menu and choose
@lab.TextBox(name)
Insert this into the section of the lab instructions where you want the drop-down menu to appear.
Replace
name
with the name you wish to use for the variable name.When a user enters text (variable value) into the text box, any lab instructions or instruction elements that use that variable name will be shown.
Drop-down Menu
Set the lab variable by configuring values in a drop-down menu. The variable is used when a lab user selects one of the options in a drop-down menu.
From the lab profile, select Edit Instructions.
Select the @lab menu and choose
@lab.DropDownList(name)[val1,val2]
Insert this into the section of the lab instructions where you want the drop-down menu to appear.
Replace
name
with the name you wish to use for the variable.Replace
val1
andval2
with variable values. Additional values can be added if needed.Configure the lab instructions to show or hide items based on the variable, by configuring one of the options below.
Lab Variables Menu
From the lab profile, select Edit Instructions.
Select the @lab menu and select the Variables tab at the top of the window.
Enter a Name that you wish to use for the
variableName
.Enter a Value that you wish to use for the
variableValue
.The lab token is generated to the right of the Value field. Copy the token and paste into lab instructions or select Insert, to insert it at the current cursor position in the lab instructions.
Configure the lab instructions to show or hide items based on the variable, by configuring one of the options below.
Using Variables in a Lab
Lab instructions and elements can be shown by using the lab variable in the lab instructions. The following methods can use a lab variable that is set by any of the methods above:
Sections
Create a section of lab instructions and IDLx elements so they can be called on as one, using the lab variable. Sections are hidden by default and are only shown when a lab variable is set that calls on the section.
From the lab profile, select Edit Instructions.
Enter the following Markdown syntax:
:::sectionName(variableName=variableValue)
lab instructions or markdown elements
:::Replace
sectionName
with the name you wish to use for the section.Replace
variableName
with the name of the variable you wish to use in the Section.Replace
variableValue
with the value paired with the variable you wish to use.Enter any lab instructions or markdown elements in the Section.
If a lab variable is set in the lab, that matches the variableName and variableValue of the section, it will be shown. Otherwise, the section will be hidden.
Textbox
Show lab instructions based on text a user enters into a textbox. The user will enter text (variable value) into the text box that corresponds with a variable name/variable value that was set using one of the methods above and any lab instructions or instruction elements that use that variable name will be shown.
It is recommended to provide the variable values in the lab instructions, so that lab users can enter a variable value that corresponds to a variable name. If a user enters text that does not correspond with a variable name, no lab instructions will be shown based on the user's input.
From the lab profile, select Edit Instructions.
Select the @lab menu and choose
@lab.TextBox(yourVariableNameHere)
.Insert this into the section of the lab instructions where you want the drop-down menu to appear.
When a user enters text (variableValue) into the text box, any lab instructions or instruction elements that use that variable name will be shown.
Drop-down Menu
Display a drop-down menu in lab instructions, where users can select an option. The options shown in the drop-down menu are variable values that were configured when the drop-down was created in the previous section.
From the lab profile, select Edit Instructions.
Select the @lab menu and choose token for the drop-down menu you created. If you created multiple drop-down menus, they will be listed here.
Insert this into the section of the lab instructions where you want the drop-down menu to appear.
Dynamic Includes From an External Repository
Lab instructions can be dynamically displayed based on the variable set in the lab and the variable value appended to the file name in the external repository.
From the lab profile, select Edit Instructions.
If the lab variable is not already set in your lab, use one of the methods above to set a lab variable.
In the lab instructions, enter a Markdown include with a lab variable appended:
!instructions[](url-@lab.Variable(variableName).md)
Replace
url
with the URL to the raw file in your external repository.Replace
variableName
with the name of the variable you wish to use.Choose an option:
Insert a drop-down menu or textbox is the lab instructions that corresponds to the variable. These can be found in the @lab menu at the top of the window.
Assemble a Launch Command URL with the lab variable appended, to launch a lab with lab instructions displayed based on the variable value appended.
Example
External repository file name:sample1-en.md
.
Include syntax with variable in file name:!instructions[](https://raw.githubusercontent.com/user1/sample1-@lab.Variable(language).md)
In this example, the variable value is en
and the variable name is language
.
API Launch
Launch a lab using the Launch API command to launch a lab for a specified user and use a lab variable in the URL as a parameter.
Assemble the URL for the API command:
https://labondemand.com/api/v3/launch?labid=100&userid=555&firstname=Joe&lastname=Smith&email=joe.smith@email.com&variableName=variableValue
.Replace information in the URL with the lab and student information; lab ID, user ID, first name, last name and email address.
Replace
variableName
with the name of the variable you wish to use.Replace
variableValue
with the value of the variable you wish to use.
For more information about the Launch command, see our Launch command API documentation.