Skip to main content
  1. Home
  2. Knowledge Base
  3. eLearning Magic Toolkit - Save and Recall Variables (User Profile)
  4. Transferring Stored Variables From WordPress Into A Storyline Activity

Transferring Stored Variables From WordPress Into A Storyline Activity

Transferring Stored Variables From WordPress Into A Storyline Activity

The eLearning Magic Toolkit plugin enables you to transfer any stored Storyline variable from the WordPress user profile back into any Storyline project. It doesn’t have to be the same Storyline project that the variables originated from! Everything you need to know is in this guide – you won’t need any coding knowledge. Follow these steps to push your stored variables from WordPress back into your Storyline project.

1. Create a WordPress page for your Storyline activity.

Just like when you created a post/page to contain your first published Storyline project, you’ll need to create another for your second Storyline activity. However, this time, you need to tick the SL Variable Transfer checkbox when publishing your new post/page. This will ensure that the current user stored variable data is accessible in any Storyline object that is published to this page.

2. Create a Trigger.

When you set up the transfer of variable data from Storyline to WordPress, you can select the trigger that causes the data to be transferred. Now you’re reversing the process, you can also choose the trigger that causes the variable data to be transferred back into Storyline from WordPress.

To do this, you need to create a new ‘Execute JavaScript’ Trigger in Storyline. You can set this to trigger as soon as the slide timeline starts on the first project slide, giving you access to all variables as soon as the user loads the new activity.

3. Add JavaScript code.

Copy and paste the following JavaScript code into your script box:

var sluser = window.parent.userCode;

fetch ('/wp-content/uploads/jsons/results_' + sluser + '.json'). then (response => {
return response.json ();
}).then (data => {

var player = GetPlayer();

player.SetVar("STORYLINE_VARIABLE_NAME", data.SL##_VARIABLENAME);

}). catch (err => {
console.log ("No Data Available.")
});

4. Edit the JavaScript code.

At this stage, it’s important to make sure you have created the Storyline Variable in your new project in the ‘Manage Project Variable’ screen. If you haven’t, the JavaScript code will have nowhere to save the transferred variable within the project.

For this block of code, the only line you need to edit is the 6th line, which starts player.SetVar,. This is where any available WordPress user profile variable can be stored as a Storyline variable.

There are 2 items within this line you’ll need to change. If you are transferring more than one variable from WordPress, you will set these up in the same way as a separate player.SetVar line item.

In WordPress, click into the User Profile screen to see which SL_ID your chosen variable was stored with. In this example, we want to bring the user’s Favourite Animal selection from the first project into this second Storyline project. This variable was stored in WordPress with the SL_ID of SL01_FavAnimal:

In the JavaScript code, replace the SL##_VARIABLE text with the name of your variable as labelled in WordPress. In this instance, it should be changed to SL01_FavAnimal. Remember that this is case sensitive!

Next, you need to replace the STORYLINE_VARIABLE_NAME text with the name of the variable you’ve created in Storyline. In this case, the variable is called FavAnimal:

The updated code for this Storyline project is now ready:

var sluser = window.parent.userCode;

fetch ('/wp-content/uploads/jsons/results_' + sluser + '.json'). then (response => {
return response.json ();
}).then (data => {

var player = GetPlayer();

player.SetVar("FavAnimal", data.SL01_FavAnimal);

}). catch (err => {
console.log ("No Data Available.")
});

Repeat the player.SetVar line for any additional variables you wish to transfer into the Storyline project.

5. Publish your project.

Publish your Storyline project with your new variable featured somewhere on the slide. When your user visits the page and interacts with this second Storyline activity, their stored variable value for ‘SL01_FavAnimal’ will be transferred into this new project. It will be displayed as soon as the timeline starts on the first slide, in our project we also went ahead and brought in our SL01_FavFood and SL01_FavColour variables also stored in WordPress:

Read the rest of our Knowledge Base pages to make the most of eLearning Magic Toolkit.

Related Articles

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.