I'm struggling with a problem. I need to make an about us page for a website. I use a template for the page and i want to fill the template with MySQL data. I use a <script> tag around the whole <div> of the personcard. The page is empty when i do this. Here is my HTML code:
<script type="text/html" id="aboutUsTemplate">
<div class="container" id="aboutUsTemplateCard">
<div class="row">
<!-- Team Member 1 -->
<div class="col-xl-6 col-md-6 mb-4">
<div class="card border-0 shadow">
<img id="personPicture" src="https://source.unsplash.com/TMgQMXoglsM/500x350" class="card-img-top" alt="">
<div class="card-body text-center">
<h5 id="personName" class="card-title mb-0">Team Member</h5>
<div id="personJob" class="card-text text-black-50">Web Developer</div>
</div>
</div>
</div>
</div>
</div>
</script>
<div id="personLocation">
</div>
I want to add cards to the view filled with data from MySQL here is my javascript code:
addPerson(aboutUsView, personData) {
const scriptTagAboutUsTemplate = $("#aboutUsTemplate", aboutUsView);
const aboutUsTemplateTarget = $("#personLocation", aboutUsView);
for (let i = 0; i < personData.length; i++) {
const aboutUsTemplate = $(scriptTagAboutUsTemplate[0].text);
const person = personData[i];
aboutUsTemplate.find("#personName").text(person.name);
aboutUsTemplate.find("#personJob").text(person.job);
aboutUsTemplate.find("#personPicture").attr("src", person.picture);
aboutUsTemplateTarget.append(aboutUsTemplate);
}
}
an issue I'm struggling with is that in the javascript line:
const aboutUsTemplate = $(scriptTagAboutUsTemplate[0].text);
is being readed as undefined, so the whole page doesn't load. Does anyone know what my problem is?