Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

This function exclude the otherone depending on which one is read for first. Why?

Alessandro MazzariAlessandro Mazzari Member Posts: 1

Why those tw ofunction exclude each others?

function templateNews() {
var assets = [
{

name: "Fiera di Vicenza",
img: "http://via.placeholder.com/360x230",
date: "01-01-2017",
publisher: "Alessandro Mazzari",
info:"Lorem ipsum dolor sit amet, consectetur adipisicing elit. Recusandae, nostrum, cumque culpa provident aliquam commodi assumenda laudantium magnam illo nostrum.",
}

];

var html = ""

assets.forEach(buildTemplate);
document.getElementById("list").innerHTML = html;

function buildTemplate(item) {
  var template = document.getElementById("template").innerHTML;
  template = template.replace("{{name}}", item.name);
  template = template.replace("{{date}}", item.date);
  template = template.replace("{{publisher}}", item.publisher);
  template = template.replace("{{link}}", item.link);
  template = template.replace("{{info}}", item.info);
  template = template.replace("{{img}}", item.img);
  html += template;
}

};

function templateSecondHand() {
var assetsProduct = [
{

  productName: "Prova",
  description: "prova",
  imgFirst : "http://via.placeholder.com/360x230",
  imgSecond : "http://via.placeholder.com/360x230",
  imgThird : "http://via.placeholder.com/360x230",
  imgFourth : "http://via.placeholder.com/360x230",
  imgFifth : "http://via.placeholder.com/360x230",
  imgSixth : "http://via.placeholder.com/360x230",
  }

  ];

  var htmlProduct = ""

  assetsProduct.forEach(buildProductTemplate);
  document.getElementById("listProduct").innerHTML = htmlProduct;

  function buildProductTemplate(itemProduct) {
    var templateProduct = document.getElementById("templateProduct").innerHTML;
    templateProduct = templateProduct.replace("{{productName}}", itemProduct.productName);
    templateProduct = templateProduct.replace("{{description}}", itemProduct.description);
    templateProduct = templateProduct.replace("{{imgFirst}}", itemProduct.imgFirst);
    templateProduct = templateProduct.replace("{{imgSecond}}", itemProduct.imgSecond);
    templateProduct = templateProduct.replace("{{imgThird}}", itemProduct.imgThird);
    templateProduct = templateProduct.replace("{{imgFourth}}", itemProduct.imgFourth);
    templateProduct = templateProduct.replace("{{imgFifth}}", itemProduct.imgFifth);
    templateProduct = templateProduct.replace("{{imgSixth}}", itemProduct.imgSixth);
    htmlProduct += templateProduct;
  }

};

Sign In or Register to comment.