java - velocity template - array not adding quotes - trying to create JSON array -


i'm trying create json array:

#set ($arraycarousel = []) #foreach ($image in $product.images)   #set ($index = $index + 1)   $arraycarousel.add("     <div class='carousel__slide u-center'>       <img id='${index}' data-code='${product.code}' class='main_image' src='${image}' data-count='$!{product.viewcount}' />     </div>"   ) #end  <script id="prog-img-${product.code}" type="text/cycle">   ${arraycarousel} </script> 

however, doesn't create quotes around each array item. pretty new velocity templates, trying figure out.

how this?

  $arraycarousel.add("${esc.q}     <div class='carousel__slide u-center'>       <img id='${index}' data-code='${product.code}' class='main_image' src='${image}' data-count='$!{product.viewcount}' />     </div>${esc.q}"   ) 

where esc reference velocity tool escapetool.

what doing adding string java list. string delimited double quotes usual. if want value contain double quotes well, need add them, escaped.

that code incredibly brittle, however. if product.code or image contains double quote, break json.

also, note relying on arraylist.tostring() having representation similar valid javascript array. seems bit fragile.


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -