Skip to content

Commit

Permalink
Dynamically change template URL path
Browse files Browse the repository at this point in the history
  • Loading branch information
ZoeBijl committed Mar 4, 2020
1 parent 15b7d0a commit 6d2a9c9
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion examples/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,14 @@
addSupportNotice()

function addSupportNotice() {
fetch('/examples/js/notice.html')
// Expected outcome '../js/app.js' OR '../../js/app.js'
var scriptSource = document.querySelector('[src$="app.js"]').getAttribute('src')
// Cut off the 'app.js' part so we know where to grab our template
var jsPath = scriptSource.split('app.js')[0]
// Append the template filename to the path
var fetchSource = jsPath + 'notice.html'

fetch(fetchSource)
.then(function(response) {
// Return notice.html as text
return response.text()
Expand Down

0 comments on commit 6d2a9c9

Please sign in to comment.