You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
html string added in template form treated as string, not html #251
functionCarousel(props){letimages=props.images.split(",");images.map(image=>image.trim());letmainImage=`<img src="${images[0]}"></img>`;letminis="";images.forEach(imageUrl=>{minis=minis.concat(`<img class="mini" src="${imageUrl}"></img>`)})console.log('a',images,minis)console.log(html`<divclass="carousel"><divclass="main"><imgsrc="${images[0]}"></img>${mainImage}<pclass="description"> Tro rilata fundamenta tabelvorto ik, o pre frazo iometo interalie. Dum otek iliard malsupera il, pro gh neigi gentonomo. Aliam multe poste ke bio, bo aha jeso samideano. Usono laŭlonge si kuo, ju apud anstataŭ ligvokalo ial, ikso tempo ut nur. Mo alta numeralo eks, timi pebi frazetvortigo no nen. Anti neniu tuj so, kapabl respondeci prepozitivo op fri.</p></div><divclass="minis">${minis}</div></div> `)}
specifically, notice these children:
<img src="${images[0]}"></img>
${mainImage}
Even though they're identical input, one is converted to a string child, one is converted to a vdom object.
This is pretty annoying. For something this small, I don't want to create a preact element. I find it weird that this option isn't available. Am I missing something? Why does htm not allow this to be parsed as html but insist on keeping it as a string?
Even though they're identical input, one is converted to a string child, one is converted to a vdom object.
Not at all, one is in fact a string, while the other is a vdom object.
To make them equal, you want this:
letmainImage=html`<imgsrc="${images[0]}"></img>`;
html is what's called a tagged template, which is a way to parse an input with a function. Therefore, it's html that transforms the string content into the vdom representation. Without it, it's just a string.
Activity
rschristian commentedon Nov 12, 2023
Not at all, one is in fact a string, while the other is a vdom object.
To make them equal, you want this:
htmlis what's called a tagged template, which is a way to parse an input with a function. Therefore, it'shtmlthat transforms the string content into the vdom representation. Without it, it's just a string.