[stringtemplate-interest] How to send parameters from template
George Pogorelschi
george.pogorelschi at gmail.com
Fri Apr 6 05:36:03 PDT 2012
Hello,
I'm trying to rewrite an online store front-end written in JSP using
StringTemplate. Everything seems to be OK but there is something that I
don't know how to implement it ST.
Here are two examples of things I want to do:
*1. Example A*
I'm generating the image url for products and because those images are
placed in different places I need to sent the image width/height based
on the location where the image is shown. For example the following code
will show the item image on a specific page:
<li id="productImages">
<div id="defaultImage">
$if(item.defaultImage.isAvailable)$
<a href="$item.defaultImage.url$"
onclick="javascript:window.open('$item.defaultImage.url$','','scrollbars=no,menubar=no,height=725,width=850,resizable=no,toolbar=no,location=no,status=no');
event.preventDefault();" title="$item.seoTitle$">
<img src="$item.defaultImage.src$" width="$item.defaultImage.width$"
height="$item.defaultImage.height$" alt="$item.seoTitle$" />
<img src="/images/zoom.png" class="zoom" alt="Zoom image -
$item.seoTitle$" />
</a>
$else$
<!-- show empty image here -->
$endif$
</div>
$if(item.images)$
<ul class="thumbnailImages">
$item.images:{image|
$if(!image.default)$
<li><a href="$image.url$"
onclick="javascript:window.open('$image.url$','','scrollbars=no,menubar=no,height=725,width=850,resizable=no,toolbar=no,location=no,status=no');
event.preventDefault();" title="$item.seoTitle$">
<img src="$image.thumbnailSrc$" width="$image.thumbnailWidth$"
height="$image.thumbnailHeight$" alt="$item.seoTitle$" /></a>
</li>
$endif$
}$
</ul>
$endif$
</li>
Because the image is automatically resized based on width/height
parameters sent to the image url:
public String getSrc() {
return response.encodeUrl(getImagePath() + "?mediaId=" + id +
"&width=" + getWidth() + "&height=" + getHeight() + "&name="
+ getTitle());
}
What I want is to be able to sent the width/height parameters to the
getSrc() method to leave the control of the image width/height to the
html/web designer.
*2. Example B*
I want to be able to identify witch option from the following select
should be selected based on a parameter that is sent to back to the page:
<span class="label">Show:</span>
<select name="itemsPerPage" class="modinput2"
onchange="location='$category.itemsPerPageUrl$&itemsPerPage=' +
this.options[this.selectedIndex].value;">
<option value="10" selected="selected">10 items on page</option>
<option value="20">20 items on page</option>
<option value="30">30 items on page</option>
<option value="40">40 items on page</option>
<option value="50">50 items on page</option>
</select>
</span>
The only solution that i'm thinking of could be a function that accept a
parameter (number of items per page) and will return true/false if that
parameter is equal with the value of the selected option. Something like
this:
$if(numberOfItems(20))$
<option value="20" selected="selected">20 items on page</option>
$else$
<option value="20">20 items on page</option>
$endif$
I don't want to hard-code the number of items per page in code as I want
to leave this control to the designer through HTML files.
Any hints how I can use ST in this kind of situation?
Thank you.
--
George Pogorelschi
Mobil (Vodafone): +40-788 43 67 43
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/stringtemplate-interest/attachments/20120406/b1685ee9/attachment.html
More information about the stringtemplate-interest
mailing list