More than one way to skin a cat...
You can do that... simply set a counter on an external html file and bring it into each course, that works. The displayed text probably won't include any course details, just a common string.
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body></body>
<script>
var start = new Date('2019-04-01');
var today = new Date();
var weeks = Math.round((today-start)/ 604800000);
var x = document.createElement('p');
var t = document.createTextNode(`Welcome to week ${weeks}!`);
x.appendChild(t);
document.body.appendChild(x);
</script>
</html>
If you want something a little more robust, built into Canvas...
Doing this using the global JavaScript themes, the code will be loaded at the bottom of the page, this means anything we modify on the page will be done after the page is fully rendered. For most users, this will happen in milliseconds and will go unnoticed.
We might also need to know if the page we are on is the course home page, this is done easiest by calling the local ENV.WIKI_PAGE.front_page true|false. Externally, we'd have to make a separate API call. But this depends on my previous question, will you be targeting an element on the page to update, or will you just add a new HTML block to the top of any page course home page.
Adding content to the content area can be problematic. The page title is not visible on the course home page unless you view it from pages. So having a target is probably best. If you have an existing element on the page that could take the Week # before or after works too.
If you're into trying the out the Developer Tools Console, you could try experimenting and decide what works best for your situation.
if (/^\/courses\/\d+.*/.test(window.location.pathname) && ENV.WIKI_PAGE.front_page) {
$.getJSON(`/api/v1/courses/${ENV.COURSE_ID}`, function(r) {
var start = new Date(r.start_at);
var today = new Date();
var weeks = Math.round((today-start)/ 604800000);
$('#course-week-count').html(`<b>${weeks}</b>`);
})
}
Your iframe solution will be a full width block, you'd have to style the content of the page in the HTML and set borders to make it look seamless. Modifying the page with JS, you can update the value within the template and it can be designed into your page.
Happy to help with either option, which direction do you like best?
This discussion post is outdated and has been archived. Please use the Community question forums and official documentation for the most current and accurate information.