Picture of Matt Leathes
Re: Reading local file
by Matt Leathes - Wednesday, 28 August 2019, 9:36 AM

So, the text file containing the data you need will be part of the course? In which case it is not a 'local file' - so you can load it and read it just like you can any other file that is part of the course. As jQuery is bundled with Adapt, it's probably easiest to use jQuery.load

Local file security restrictions apply when you are trying to get the course to load a file from the end user's computer i.e. trying to get a webpage to load a file like C:\users\jason\file.txt will not be allowed, for reasons that should be pretty obvious ;-)

Personally I would favour simply putting the data you need in course.json - as that file is already loaded that means one less step to get at the data you need. But equally putting the data in a .txt file will work too and if that makes life easier for your tutors then that's worth doing. If you were to put the zip file in the 'course root' (alongside index.html) then they wouldn't even have to unzip the zip file in many cases, they could simply drop their version of the .txt file onto the .zip file to add it (depending on what zip utility they have).

individual components can read the id from sessionStorage

I might be missing something but using session storage seems unnecessary here. As Adapt is a single page application, you shouldn't need to use session storage. You can simply add your data to the Adapt object e.g.:

var Adapt = require('core/js/adapt');
if (!Adapt.config.dbInfo) {
  Adapt.config.dbInfo = {
    dbId: 'foo',
    dbAccessKey: 'bar'

Hope this helps?