Below is a sample JQUERY template that is to be embedded into a velocity template.
<script id="appTemplate" type="text/x-jquery-tmpl">
<li>
<a href="${DURL}">
<img src="${IURL}" class="f-left" width="39" alt="${IDESC}" title="${IDESC}" />
</a>
<div class="block"> <a href="${DURL}">${AN}</a>
{{each(j,rating) PL}}
{{if rating["AAR"]}}
<div style="clear:both;"></div>
<div id="r${j}" title="${rating['AAR']} star rating">
<img class ="platformIcon" src="${ rating['AAR'] ? rating['PIURL'] : '' }"
alt="${ rating['AAR'] ? rating['PIDESC'] : '' }"></img>
{{if rating["AAR"] % 1 == 0}}
<img class="stars ratings_stars_img" src="./resources/images/${rating['AAR'] - rating['AAR']%1}_star_rating.png"
alt="${rating['AAR'] - rating['AAR']%1} star rating"></img>
{{/if}}
{{if rating["AAR"] % 1 != 0}}
<img class="stars ratings_stars_img" src="./resources/images/${rating['AAR'] - rating['AAR']%1}.5_star_rating.png"
alt="${rating['AAR']} star rating"></img>
{{/if}}
<div class="total_votes">${rating["NR"] ? rating["NR"]+' Ratings': ''} </div>
</div>
{{/if}}
{{/each}}
</div>
</li>
</script>
Which is fine except that Percussion’s Apache Velocity Parser barfs on things like ${rating[‘AAR’]}.
So the above must be transformed into something like this.
#set($hack2 = '${rating["AAR"]}')
#set($hack3 = './resources/images/${rating["AAR"] - rating["AAR"]%1}_star_rating.png')
#set($hack4 = '${rating["AAR"] - rating["AAR"]%1} star rating')
#set($hack5 = './resources/images/${rating["AAR"] - rating["AAR"]%1}.5_star_rating.png')
#set($hack6 = '${rating["AAR"]} star rating')
#set($hack7 = '${rating["NR"]')
<script id="appTemplate" type="text/x-jquery-tmpl">
<li>
<a href="${DURL}">
<img src="${IURL}" class="f-left" width="39" alt="${IDESC}" title="${IDESC}" />
</a>
<div class="block"> <a href="${DURL}">${AN}</a>
{{each(j,rating) PL}}
{{if rating["AAR"]}}
<div style="clear:both;"></div>
<div id="r${j}" title='$hack2 star rating'>
<img class ="platformIcon" src="${ rating['AAR'] ? rating['PIURL'] : '' }"
alt="${ rating['AAR'] ? rating['PIDESC'] : '' }"></img>
{{if rating["AAR"] % 1 == 0}}
<img class="stars ratings_stars_img" src='$hack3'
alt='$hack4'></img>
{{/if}}
{{if rating["AAR"] % 1 != 0}}
<img class="stars ratings_stars_img" src='$hack5'
alt='$hack6'></img>
{{/if}}
<div class="total_votes">$hack7 ? rating["NR"]+' Ratings': ''} </div>
</div>
{{/if}}
{{/each}}
</div>
</li>
</script>
This is a real pain to do every time the JSON Template changes.
It would be really nice if we could use #[[ ]]# to hide stuff from the parser out as documented in the apache velocity manual
See Unparsed Content section at the bottom of this page http://velocity.apache.org/engine/devel/vtl-reference-guide.html
#[[
Parser doesn’t see this.
At all…
]]#
Somehow I seem to be getting velocity parser errors on items enclosed in these symbols.