I have a table populated from some JSON in a JS file.
data.js looks like this:
var data = [
{
title: "Avengers Endgame Trailer",
year: 2019,
type: "MOV",
file: "video1.mp4"
},
{
title: "Avengers Infinity War Poster",
year: 2018,
type: "PNG",
file: "image1.png"
}
];
The data is read in a JS function in my functions.js file (which writes the actual table rows).
function populateTable() {
for (var i = 0; i < data.length; i++) {
if (data[i].type == "MOV") {
var row = '<tr><td><a href="video.html?=' + data[i].file + '">' + data[i].title + "</a></td>";
row += "<td>" + data[i].year + "</td></tr>";
$("#contents").append(row);
} else {
var row = '<tr><td><a href="image.html?=' + data[i].file + '">' + data[i].title + "</a></td>";
row += "<td>" + data[i].year + "</td></tr>";
$("#contents").append(row);
}
}
}
What I'm trying to figure out is how to allow the link offs for each item to use a different template file. I wrote some dummy code in the HREF above but that's obviously not correct.
For templates, I have two: video.html and image.html. I'd like to pass the filename of the index tapped as a parameter into the template files so it can display the correct file, but I'm unsure what to do?
As an example the video.html template file looks like this:
<html>
<body>
<div class="container">
<video autoplay muted loop id="main">
<source src="{filenameGoesHere?}" type="video/mp4">
Your browser does not support HTML5 video.
</video>
</div>
</body>
</html>