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
Post a Comment