Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

CFLOOP Help

Explorer ,
May 16, 2008 May 16, 2008
I have a simple loop

<cfloop list="#prodDetails.matchProds#" index="matching" delimiters=",">
<cfoutput>
<a href="/catalog/?ProductID=#matching#&Category=#URL.category#"> #matching#</a><br />
</cfoutput>
</cfloop>

That currents displays results as:

Value 1
Value 2
Value 3
etc...

I am trying to figure out how to make the out appear as such:

Value 1 Value 2
Value 3 Value 4
Value 5 etc...

Any help here would be much appreciated. Regards.
TOPICS
Advanced techniques
409
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 16, 2008 May 16, 2008
bfinelsen wrote:
>
> Value 1 Value 2
> Value 3 Value 4
> Value 5 etc...
>
> Any help here would be much appreciated. Regards.
>

You need a conditional <cfif> block around the <br/> tag.

The condition for this if block needs to be true when you want the <br/>
displayed and when it is not.

If you want to and only two elements between each <br/> tag, you could
get by with a boolean that is flipped back and forth.

If you want more flexibility where you can have different numbers of
element between the <br/> tags, use a counter and the MOD operator.

Is that enough help?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
May 16, 2008 May 16, 2008
Something like this?

<cfloop list="#prodDetails.matchProds#" index="matching" delimiters=",">
<cfoutput>
<cfif matching MOD 2 EQ 0>
<a href="/catalog/?ProductID=#matching#&Category=#URL.category#"> #matching#</a><br />
<cfelse>
<a href="/catalog/?ProductID=#matching#&Category=#URL.category#"> #matching#</a>&nbsp
</cfif>
</cfoutput>
</cfloop>

Phil
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 16, 2008 May 16, 2008
paross1 wrote:
> Something like this?
>
> <cfloop list="#prodDetails.matchProds#" index="matching" delimiters=",">
> <cfoutput>
> <cfif matching MOD 2 EQ 0>
> <a href="/catalog/?ProductID=#matching#&Category=#URL.category#">
> #matching#</a><br />
> <cfelse>
> <a href="/catalog/?ProductID=#matching#&Category=#URL.category#">
> #matching#</a>&nbsp
> </cfif>
> </cfoutput>
> </cfloop>
>
> Phil
>

Somewhat, except that I would just put the <cfif> block around the <br/>
tag, not the entire <a...> tag that is the same in both clauses.

But <cfif matching MOD 2> does not work in this case. Since this is a
list loop 'matching' is going to be a string containing each element in
the list.

One would need to either create an independent counter to be used in the
MOD clause or use a listFind() function to get the numeric position from
the list from which the string in 'matching' came.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 16, 2008 May 16, 2008
Thank you! Using your suggestion, I have used a boolean type of syntax to make it work perfectly. Many thanks.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 16, 2008 May 16, 2008
LATEST
To make that code more efficient, put the loop inside the cfoutput instead of the way you have it now.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources