Picture of Matt Leathes
Re: Get Course Title programmatically
by Matt Leathes - Friday, 9 October 2020, 2:00 PM
 

Yes:
Adapt.course.get('displayTitle');
or:
Adapt.course.get('title');
If you want the plain text version. For example, the code that applies the course title to the document (broswer window/tab title) uses the plain text version.

You can also include it in a handlebars template by putting {{import_adapt}} in the .hbs file (usually at the top) then using {{{Adapt.course.displayTitle}}} or {{Adapt.course.title}} where you want to show it.

You can do something similar in the .json files as well, e.g. try adding {{import_adapt}}{{{Adapt.course.displayTitle}}} into the body of a text component.

BTW you haven't said what version of Adapt you're using, I've assumed it's fairly recent but if it's quite old (v2.x) then some of this won't work

Picture of Chris Gillison
Re: Get Course Title programmatically
by Chris Gillison - Wednesday, 2 December 2020, 7:54 PM
 

Hi Matt,

This is great! Can you do a similar thing with offlineStorage?

I'm using the nameInput extension. Iser fills in the text field then hits a submit button with the code

Adapt.offlineStorage.set('_username', this.getUserInput());

I want to be able to call the retrieve the _username in the .json files if possible. I tried

{{import_adapt}}{{{Adapt.offlineStorage._username}}}

in the .json component body, but nothing displayed.

Picture of Chris Gillison
Re: Get Course Title programmatically
by Chris Gillison - Wednesday, 2 December 2020, 9:59 PM
 

So I've managed to set & retrieve the username by changing the button code to:

Adapt.course.set('_username', this.getUserInput());

and using the format illustrated above to retrieve the data:

{{import_adapt}}{{{Adapt.course._username}}}

So, is that a 'bad' way to proceed (e.g. impacts elsewhere) or is that ok?

It's framework 4.3.0 BTW, and I guess I should say I'm trying to set something up whereby a client without an LMS can have personalised content & certificate.

Many thanks.

Picture of Oliver Foster
Re: Get Course Title programmatically
by Oliver Foster - Thursday, 3 December 2020, 10:15 AM
 

That seems fine.

{{import_adapt}}

Only imports the json from the models.

 

You could also register a helper with Handlebars.
https://handlebarsjs.com/guide/#custom-helpers

Handlebars.registerHelper('myextensionprefix_username', () => this.getUserInput());

Then:

{{myextensionprefix_username}}

Picture of Chris Gillison
Re: Get Course Title programmatically
by Chris Gillison - Thursday, 3 December 2020, 10:27 AM
 

Great. Thanks Oliver.