You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@freemarker.apache.org by Ingo Mahnke <in...@quvion.org> on 2017/03/06 15:36:12 UTC

Question about String Concatenation [FM2]

Hallo,
one question.

This works:
<#list imagesLayout?split(";") as x>
            <table border="0" cellspacing="0" cellpadding="0" style="width:100%">
                <tr>
                    <#list x?split("-") as y>
                        <#assign s = "image"+y>
                        <td class="qvImageGalleryImage"><@img width="100%" height="185" style="width:100%;" name="${s}"/></td>
                    </#list>
                </tr>
            </table>
        </#list>



Why this will not work:
<#list imagesLayout?split(";") as x>
            <table border="0" cellspacing="0" cellpadding="0" style="width:100%">
                <tr>
                    <#list x?split("-") as y>
                          <td class="qvImageGalleryImage"><@img width="100%" height="185" style="width:100%;" name="${"image"+y}"/></td>
                    </#list>
                </tr>
            </table>
        </#list>


Why I have to use the "assign"?



Thank you
Ingo

Re: Question about String Concatenation [FM2]

Posted by Daniel Dekany <dd...@freemail.hu>.
Monday, March 6, 2017, 4:36:12 PM, Ingo Mahnke wrote:

> Hallo,
> one question.
>
> This works:
> <#list imagesLayout?split(";") as x>
>             <table border="0" cellspacing="0" cellpadding="0" style="width:100%">
>                 <tr>
>                     <#list x?split("-") as y>
>                         <#assign s = "image"+y>
>                         <td class="qvImageGalleryImage"><@img
> width="100%" height="185" style="width:100%;" name="${s}"/></td>
>                     </#list>
>                 </tr>
>             </table>
>         </#list>
>
>
>
> Why this will not work:
> <#list imagesLayout?split(";") as x>
>             <table border="0" cellspacing="0" cellpadding="0" style="width:100%">
>                 <tr>
>                     <#list x?split("-") as y>
>                           <td class="qvImageGalleryImage"><@img
> width="100%" height="185" style="width:100%;" name="${"image"+y}"/></td>
>                     </#list>
>                 </tr>
>             </table>
>         </#list>
>
>
> Why I have to use the "assign"?

It should be

   name="image"+y

or

  name="image${y}"

The problem occurs because the @img tag isn't just static like HTML,
so the parameters to it are FTL expressions. "${"image"+y}" isn't a
valid expression (the quotation marks are messed up). "${'image'+y}"
would be valid, but it's not the shortest way.

> Thank you
> Ingo

-- 
Thanks,
 Daniel Dekany