Here's something I'm trying in the global javascript, and it seems to work.
// search and replace
function replaceInText(element, pattern, replacement) {
//console.log(pattern);
//console.log(replacement);
for (let node of element.childNodes) {
switch (node.nodeType) {
case Node.ELEMENT_NODE:
attr='href';
if (node.hasAttribute(attr)){
//console.log(node);
node.setAttribute(attr, node.getAttribute(attr).replace(pattern, replacement));
}
replaceInText(node, pattern, replacement);
break;
case Node.TEXT_NODE:
node.textContent = node.textContent.replace(pattern, replacement);
break;
case Node.DOCUMENT_NODE:
replaceInText(node, pattern, replacement);
}
}
}
function replaceLocalVariables(){
var user_content=document.getElementsByClassName('user_content');
Array.prototype.forEach.call(user_content, function(el) {
// define ENV fields here that you want to process
var fieldsToWork = ['ENV.sis_course_id','ENV.current_user.display_name'];
for (var i=0; i<fieldsToWork.length; i++){
var searchFor = fieldsToWork[i];
var re = new RegExp(searchFor, "g");
replaceInText(el, re, eval(fieldsToWork[i]));
}
});
}
$(document).ready(function () {
if (/^\/courses\/[0-9]+/.test(window.location.pathname)){
ENV.sis_course_id=$('#breadcrumbs a')[1].innerText;
replaceLocalVariables();
}
});
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.