[stringtemplate-interest] How to send parameters from template
Terence Parr
parrt at cs.usfca.edu
Sun Apr 8 15:49:49 PDT 2012
Can you do something with a formatter / renderer object in ST?
T
On Apr 8, 2012, at 11:45 AM, George Pogorelschi wrote:
> You point is correct but in my case i can't compose the src in the template because the getSrc() method is actually a call to urlrewrite library (response.encodeUrl()) and it will transform the src string to a new string based on the urlrewrite configuration.
>
> In my first example the getSrc() call for a string like "/media/product/?mediaId=10&width=140&height=140&name=some-seo-url" will return a seo enabled src string (eg. "/images/some-seo-url__10__140_140") that is configurable in the urlrewrite xml config file. This will allow the owner of the store to customize his SEO url's.
>
> George Pogorelschi
>
> Mobil (Vodafone): +40-788 43 67 43
>
> On 4/8/2012 7:50 PM, Terence Parr wrote:
>>
>> Hi. Yeah,You cannot pass parameters to getters. no information from the template is allowed to go back into the model without entangling the model and the view. Looks to me like you're getSrc() has code that is creating output, which defeats the purpose of ST. The rules of strict separation suggested that no output characters can be computed in the model.
>>
>> The view should not be trying to compute which one is selected for your 2nd example. That is information that should be precomputed and sent to the view.
>> Ter
>> On Apr 6, 2012, at 5:36 AM, George Pogorelschi wrote:
>>
>>> 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
>>> _______________________________________________
>>> stringtemplate-interest mailing list
>>> stringtemplate-interest at antlr.org
>>> http://www.antlr.org/mailman/listinfo/stringtemplate-interest
>>
> _______________________________________________
> stringtemplate-interest mailing list
> stringtemplate-interest at antlr.org
> http://www.antlr.org/mailman/listinfo/stringtemplate-interest
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/stringtemplate-interest/attachments/20120408/0c6826e8/attachment.html
More information about the stringtemplate-interest
mailing list