Global js ENV object available and what fields?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I'm developing a custom theme and the global .js override file I'm working with depends on the availability of the ENV array/object and the existence of the COURSE field and the child long_name field.
let year = parseInt(ENV.COURSE.long_name.split(' ')[1]);
The home page of the course has this field, but the syllabus page does not.
Is there any documentation on what certain areas of a Canvas course provide certain fields in the ENV object?
What else can I do to reliably determine what the name of any given course with this custom theme applied on all pages within a course?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
When I talked with a Canvas engineer in April 2017, he told me that the ENV variable was not managed by a single group. If a page (like the syllabus) needed certain functionality, a quick fix was to add it to the ENV variable for that page. I also gathered (this may be my take on it) that they were not encouraging adding new things to the environment, but would rather people "do it right". If I recall, the mobile apps didn't have an ENV to work with.
The absence of formal public documentation makes it fall under Instructure's "use at your own risk" policy, which is really more of a "we would rather you not use this at all, but if you must, use at your own risk, realizing nothing is guaranteed and don't complain to us if something breaks" policy.
Canvas may have something internally and just chosen not to share it, but it didn't sound like it.
None of that gives you a list, so I took a look at the source code.
It seems that most of the ENV variable is created by the use of js_env and within a controller file. Many of them appear in the application_controller, which would make sense. Starting in line 202 of that file, they define @js_env and then add about 27 properties. That might be the closest there is to a global list in a single spot, but then the js_env is modified several other times in the file, so even that initial list isn't complete.
In other files, such as the announcements_controller, you will see things that are added for the announcements.