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

CFLOOP Help

Explorer ,
May 16, 2008 May 16, 2008

Copy link to clipboard

Copied

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

Views

355

Translate

Translate

Report

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

Copy link to clipboard

Copied

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?

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

Thank you! Using your suggestion, I have used a boolean type of syntax to make it work perfectly. Many thanks.

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

LATEST
To make that code more efficient, put the loop inside the cfoutput instead of the way you have it now.

Votes

Translate

Translate

Report

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
Documentation