Skip to content

Instantly share code, notes, and snippets.

@batazo
Last active August 10, 2021 19:32
Show Gist options
  • Select an option

  • Save batazo/c96543ad7b92e74d5e1f87dc9519f2b8 to your computer and use it in GitHub Desktop.

Select an option

Save batazo/c96543ad7b92e74d5e1f87dc9519f2b8 to your computer and use it in GitHub Desktop.
User Template with BIND
<div id="userwelcomeDiv">
{{ User Welcome Panels loading... }}
</div>
let users = [
{name: "Zoltán", city: "Budapest"},
{name: "Éva", city: "Debrecen"},
{name: "István", city: "Kecskemét"},
{name: "Katalin", city: "Szeged"},
{name: "János", city: "Sopron"},
{name: "Fanni", city: "Tatabánya"}
]
console.table(users)
function welcomePanel(name, city) {
let welcomeTemplate = function () {
return `<div class="welcomePanels">Welcome here <span class="green">${this.name}</span> from ${this.city}!</div>`;
};
let welcomeuser = welcomeTemplate.bind({
name: name.toUpperCase(),
city: city
})();
return welcomeuser
}
function renderWelcomePanels(){
userwelcomeDiv.innerHTML = ""
for(let user of users){
userwelcomeDiv.innerHTML += welcomePanel(user.name, user.city)
}
}
renderWelcomePanels()
.welcomePanels {
margin: 10px;
padding: 10px;
border: 3px solid darkgray;
background-color: lightgray;
}
.green {
color: green;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment