1

I'm rendering some JSON using Views and Views Datasource and due to a bug in Views Datasource, I can't seem to get the output rendered properly. So, I'm looking for a workaround.

What hook can I implement in my theme or module that will give me the final string that is about to sent back to the browser that will give me one last chance to alter it?

EDIT: I was in a hurry and worded that poorly. When I say the page won't render properly, I mean that the bug in Views Datasource doesn't use the proper data formatters for the data fields. I'm getting JSON back just fine, but some of the values within the JSON are not properly processed by the relevant module formatters. In this example, the Video field can contain a Video URL and a Thumbnail Image URL. The view is configured to display a Thumbnail Image URL, but due to the bug in Views Datasource, it is displaying the Video URL instead.

I can't just change the render array, because Views Datasource is not generating its output using a render array.

1
  • If you execute a function that alters a document on a hook that executes when the document is altered, wouldn't it create an infinite recursion?
    – Shanimal
    Commented Apr 8, 2013 at 17:37

4 Answers 4

1

I highly recommend you not to alter the page output when you clearly know where the bug is. See Bala's answer. Or may be you want to let us know what is the exact problem ?

To answer your question, to alter the content that is going to be rendered, use hook_page_alter

1
  • It's a misunderstanding of what and where the bug is. I updated my post because I did a poor job of explaining it at first. Commented Jan 5, 2013 at 17:25
1

Try hook_page_alter, it lets you alter the final page render array

You may also be interested in

drupal_json_encode

2
  • Original comment was from mobile. Anyways, see the hook_page_alter documentation link now added for more information. Commented Jan 5, 2013 at 9:52
  • I updated my description. Altering the render array is not a viable solution because Views Datasource is not producing its output using a render array. This hook is not called when I fetch the JSON from the url (Yes, I flushed my cache). Commented Jan 5, 2013 at 17:23
0

I am also having this issue when using View Datasource module but i solved it by changing the views-views-xml-style-raw.tpl.php file

located under "sites\all\modules\views_datasource-6.x-1.0-beta2\views_datasource\theme\"

Replace drupal_set_header("Content-Type: $content_type; charset=utf-8"); with

drupal_set_header('Content-Type: text/xml;');

I hope it will works for you too.

1
  • I updated my post. Sorry for the incredibly poor description of "not rendering properly." I'm getting well formed and usable JSON, the bug in Views Datasource is that the wrong data formatters are used to produce the values so I need to swap new values into the json. It's not using a render array, so I just need to alter the raw text being sent back. Commented Jan 5, 2013 at 17:24
0

For Drupal 7:

// Implement HOOK_page_alter. function MY_MODULE_page_alter(&$page) { // Add our processing to the #post_render functions. $page['#post_render'][] = 'MY_MODULE_page_post_render'; }

function MY_MODULE_page_post_render($html) { // Do something to the HTML for the page. $html = str_replace('apples', 'oranges', $html); return $html; }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.