Skip Navigation

[Resolved] Strange output when needing raw output render_view since update 1.11.1

This support ticket is created 8 years, 4 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
- - 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00
- - - - - - -

Supporter timezone: Asia/Ho_Chi_Minh (GMT+07:00)

This topic contains 4 replies, has 2 voices.

Last updated by Beda 8 years, 4 months ago.

Assisted by: Beda.

Author
Posts
#350819

I am trying to: Before version 1.11.1 we were using the below URL which renders an json page (Custom API). We are using render_view which was working perfectly fine till version 1.11.1, i did a raw output and saw some extra output since the update which puts an extra div with pagination info (pagination is off btw). I cannot seem to find an option to completly disable this and only let the view (api_aanbod) output raw stuf without the pagination information (<div>):

<div id="wpv-view-layout-7291-CATTR1afde3c7beb41325c0f4b3f70377160c" class="js-wpv-view-layout js-wpv-layout-responsive" data-viewnumber="7291-CATTR1afde3c7beb41325c0f4b3f70377160c" data-pagination="{"ajax":"false","effect":"fade","duration":500,"stop_rollover":"false","cache_pages":true,"preload_pages":true,"pre_reach":1,"spinner":"default","spinner_image":"hidden link","callback_next":"","max_pages":0,"page":1}">
<input type="hidden" id="js-wpv-pagination-page-permalink" value="/woningapp/docs/api/get/aanbod?plaatsen=1%2C2%2C3%2C4&prijs_id=2&types=1%2C2%2C3%2C4&wpv_view_count=7291-CATTR1afde3c7beb41325c0f4b3f70377160c&wpv_paged=1" />

The problem is that with the extra div i cannot render a valid json object.

I visited this URL: hidden link

I expected to see: only json code without the extra div

Instead, I got: see above!

#350822

btw. on the live site we are still using 1.10.1 and the output is still completely raw as expected, that's why we postponed updating to 1.11.1:

hidden link

#350867

Thank you for contacting us here in the Support Forum

This is the expected behavior since Views 1.11.1

It is expected because Views is and never was intended to be a Software to provide Data, but to display it.

Our Developers are though considering a new feature, so to choose by settings if to Provide Data with a certain View, or display it.

For now, you would need to follow the below instructions.

Apply the below filter to your View, in functions.php:

add_filter( 'wpv_filter_wpv_view_shortcode_output', 'prefix_clean_view_output', 5, 2 );

function prefix_clean_view_output( $out, $id ) {
if ( $id == '375' ) { //Adjust this ID to your View's ID
$start = strpos( $out, '<!-- wpv-loop-start -->' );
if ( 
$start !== false
&& strrpos( $out, '<!-- wpv-loop-end -->', $start ) !== false
) {
$start = $start + strlen( '<!-- wpv-loop-start -->' );
$out = substr( $out , $start );
$end = strrpos( $out, '<!-- wpv-loop-end -->' );
$out = substr( $out, 0, $end );
}
}
return $out;
}

What it does:
- It hooks early in the View output.
- Priority 5 is mandatory as we already do some other cleaning at priority 10.
- It only affects a View with an ID of 375, adjust acordingly if needed.
- It only affects Views with actual results: if the View matches no result, the same “No items found” or whatever you have between the wpv-no-items-found shortcode applies.
- It returns only what is between the HTML comments <!– wpv-loop-start –> and <!– wpv-loop-end –> , excluding them. Only content between those HTML comments is returned, as is.

Notice that, with this applied to a given View ID:
- Pagination, specially AJAX pagination, will not work.
- Parametric search, specially AJAXed parametric search, will not work.
- Other future features will not work either.

But also notice that this only clears the View structure.

Building as example JSON inside a View output is wrong because we can not address quoting problems.
It is not the best approach, generally speaking in terms of Best Coding Practices.

This user here provided a Custom Solution to this as well:
https://toolset.com/forums/topic/error-using-cred_generic_field-to-let-user-select-the-post-author/#post-347121

Please let me know if the above solution works for you, I look forward to your reply!

Thank you for your patience.

#350875

I'm not quite sure if i agree with you on this one 😉

I understand that views was developed as software to display data but not to provide it, but as from a developer perspective i'm keen on what software would unexpected output to display.

I really think that if i explicit tell a view to NOT use pagination, i would not expect it to output pagination helper divs, because they would not be used anyway and is only overhead fmpov.

However it would be very nice if there would be an option like it is in a view template to output the rendering as raw if that is what you mean.

The above URL: hidden link is unfortunately not accessible for me (needs credentials)

I will try your workaround and keep you posted, thanks for your reply and help!

#350897

I deeply apologize, here is the correct URL:
https://toolset.com/forums/topic/error-using-cred_generic_field-to-let-user-select-the-post-author/#post-347121

I also edited the original Post of mine.

We will add a feature in future release, where using a View in conjunction with a Content Template will be possible to set to "raw" output.

Please don't hesitate to inform me if you stumble upon issues with the code.

The default HTML not only is for pagination, but also to lay the ground for future features, such as "Front End Sort By" features.
We do not always know what will be included in the View as some of the features will be added via ShortCode and not by Settings such as query or pagination.

This is why the code is wrapped by default.

Please do not hesitate to open a new thread if other issues or problems arise

Thank you for your patience.

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