Skip Navigation

[Resolved] Code bug in the loop wizard?

This thread is resolved. Here is a description of the problem and solution.

Problem: It looks like there is an error in the code produced by the Loop Wizard for a multi-column grid or table. The syntax highlighter shows an error, and it looks like there is an extra closing div.

Solution: The syntax error here is actually a false reading, because of the way loop output works with rows and columns. It looks like there are extra closing divs because the first column always opens the row, but then the row may be closed in the pad-last item, or in the other index item.

Relevant Documentation:
https://toolset.com/documentation/user-guides/digging-into-view-outputs/

This support ticket is created 5 years, 10 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 6 replies, has 2 voices.

Last updated by peterB-20 5 years, 10 months ago.

Assisted by: Christian Cox.

Author
Posts
#904624
2018-05-27 21_36_21-Edit View ‹ VDS — WordPress.png
2018-05-27 21_33_22-Edit View ‹ VDS — WordPress.png

Hi,

I think I found a bug in the Loop Wizard, to much code in Bootstrap grid and Table-based grid. See images

Cheers
Peter

[wpv-layout-start]
	[wpv-items-found]
	<!-- wpv-loop-start -->
	<wpv-loop wrap="1" pad="true">
		[wpv-item index=1]
		<div class="row ">
			<div class="col-sm-12">[wpv-post-body view_template="Loop item in Blogs - voor persoonlijke teampag. (views)"]</div>
		</div>
		[wpv-item index=other]
			<div class="col-sm-12">[wpv-post-body view_template="Loop item in Blogs - voor persoonlijke teampag. (views)"]</div>
		[wpv-item index=pad]
			<div class="col-sm-12"></div>
		[wpv-item index=pad-last]
			<div class="col-sm-12"></div>
		</div>           <========================================================
	</wpv-loop>
	<!-- wpv-loop-end -->
	[/wpv-items-found]
	[wpv-no-items-found]
		<strong>[wpml-string context="wpv-views"]No items found[/wpml-string]</strong>
	[/wpv-no-items-found]
[wpv-layout-end]
[wpv-layout-start]
	[wpv-items-found]
	<!-- wpv-loop-start -->
	<table width="100%" class="wpv-loop js-wpv-loop">
	<wpv-loop wrap="2" pad="true">
		[wpv-item index=1]
		<tr>
			<td>
				[wpv-post-body view_template="Loop item in Blogs - voor persoonlijke teampag. (views)"]
			</td>
		[wpv-item index=other]
			<td>
				[wpv-post-body view_template="Loop item in Blogs - voor persoonlijke teampag. (views)"]
			</td>
		[wpv-item index=2]
			<td>
				[wpv-post-body view_template="Loop item in Blogs - voor persoonlijke teampag. (views)"]
			</td>
		</tr>
		[wpv-item index=pad]
			<td></td>
		[wpv-item index=pad-last]
			<td></td>
		</tr>           <==============================================================
	</wpv-loop>
	</table>
	<!-- wpv-loop-end -->
	[/wpv-items-found]
	[wpv-no-items-found]
		<strong>[wpml-string context="wpv-views"]No items found[/wpml-string]</strong>
	[/wpv-no-items-found]
[wpv-layout-end]
#904631
Screen Shot 2018-05-27 at 3.55.36 PM.png

I don't see anything that will produce invalid markup here. Take a look at this screenshot. In the first loop example, your loop is set up with wrap="1". That means there will only ever be one item per row, so index=other, index=pad, and index=pad-last are irrelevant and will never be used. Nothing to worry about here unless you modify the "wrap" settings, in which case you should recreate the loop using the Loop Wizard again.

In the second loop example, the code is accurate. Wrap is set to "2" with pad=true, meaning there will always be two results per row. In the case of an even number of results in the View, the wpv-item index=1 and wpv-item index=2 blocks will be rendered. That includes an opening tr and a closing tr. In the case of an odd number of results, index=1 and index=pad-last will be rendered. That includes an opening tr and a closing tr. So in either case, the number of opening and closing tr tags is correct.

#907910

Sorry for my late reply, I was on a business trip.
Okay, but it is odd. The editor indicates an error in both situations and in both situations there is a closing tag but no opening tag.

When you say it is okay, it is fine with me.

Cheers
Peter

#907959

The editor indicates an error in both situations
I agree it's a bit confusing because the code editor isn't smart enough to account for the index-based loop structure. I don't think you have anything to worry about here.

there is a closing tag but no opening tag.
Keep in mind that if there were more than 1 item, the first wpv-item would look like this:

[wpv-item index=1]
        <div class="row ">
            <div class="col-sm-12">[wpv-post-body view_template="Loop item in Blogs - voor persoonlijke teampag. (views)"]</div>
 [wpv-item index=2]
...

You can see that in this case, the opening tag would be in the first wpv-item block, and that tag would be left open until the last item or the pad-last item. Then the extra closing div you see in the code now would make more sense.

#908043

Aha, clear so don't correct the errors in the loop editor, that is a bit tricky. Thanks for the explanation,

#908453

Great, let me know if you have problems with that, otherwise I believe we can close this ticket out.

#908455

Perfect, thx!

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.