Return to Jive Software

Skip navigation
1,115 Views 3 Replies Last post: Oct 30, 2009 7:00 PM by Airman85 RSS
Airman85 Novice 20 posts since
Oct 30, 2009
Currently Being Moderated

Oct 30, 2009 4:35 PM

FreeMarker Help! (Looping Through 2 Lists)

Hey Everyone,

 

Was going to see if anyone could help me out with a problem I'm trying to solve. Basically in a nutshell, I have 2 lists that I am iterating through, and I am trying to match index values of the items in each list up. So for example:

 

property1 = Bill, Steve

property2 = Gates, Jobs

 

And my code looks as follows:

 

 

<#if  (property1')?exists &&  (property2')?exists)>
     <#list JiveGlobals.getJiveProperty('property1')?split(",") as metaNAME>
          <#list JiveGlobals.getJiveProperty('property2')?split("-") as metaVALUE>
               <meta name="${metaNAME}" content="${metaVALUE}">
          </#list>
     </#list>
</#if>

 

 

This code prints out:

 

 

<meta name="Bill" content="Gates">     
<meta name="Bill" content="Jobs">     
<meta name=" Steve" content="Gates">     
<meta name=" Steve" content="Jobs">

 

 

 

 

But I want them to only print out the same index values, so the output I WANT is:

 

 

<meta name="Bill" content="Gates">
<meta name=" Steve" content="Jobs">

 

 

 

I've been wracking my brain trying to figure out how I can do this, if anyone can offer any advice / help, I would GREATLY appreciate it!

 

Thanks in advance!!

kevin.imber Jive Employee 2,587 posts since
Oct 19, 2009
Currently Being Moderated
Oct 30, 2009 5:06 PM in response to: Airman85
Re: FreeMarker Help! (Looping Through 2 Lists)

Hello,

 

I did a little checking on freemarker, and from what I found, you want to have:

<#if  (property1')?exists &&  (property2')?exists)>

      <#list JiveGlobals.getJiveProperty('property1')?split(",") as metaNAME>
            <meta name="${metaNAME}" content="${property2[metaNAME_index]}"> 
      </#list>
 </#if>

The reason you were getting that output is that you were nesting a loop inside another, so for every iteration of the outer loop you ran through the entire inner loop.  This way, you'll only run through the outer loop, and since you index the last-name-list with your loop variable, your last names will stay in sequence with your first names.  Hope that helps.

 

Thanks,

Kevin

More Like This

  • Retrieving data ...

Bookmarked By (0)

To better serve our customers we have included functionality to automatically follow up on a case after it has been idle for more than 5 days, and then auto close after an additional 3 days of inactivity. Choose No to acknowledge that this case will remain idle for longer than 5 days.
Making cases public allows other customers to learn from the solution of the case. It can also be used to gain feedback from others in the community. Ask our Support Engineers for more info, but we encourage you to make your cases public.