3

I require threaded comments with pager but instead of loading a new page when pager is clicked, I want the data to be loaded via ajax. There are 2 problems I have with page load -

  1. Loading a new page itself
  2. I have a number of contents with there comments on a single page and clicking a pager for any comments list takes me to a new page, hence a new page for all the comments lists on the page, not only the one I had clicked.

Any help is appreciated. Thanks.

2

install views module and create a new view with comments as base, block as output, and the actual node as context. set it to use ajax, et voilà.

then - add this block to the content section and limit its visibilty to the corresponding content type.

to make sure the JS of views is added you have to add them manually. so in you template.php - add function YOURTHEME_preprocess_page(&$vars, $hook) { //Reload the javascript into the scripts. $vars['scripts'] = drupal_get_js(); } - may be even better to check the $vars if you're on the desired content type

  • Actually my use case is this - a content type with reference to another content type(question with ref to answers)The answer content type has comments. Hence multiple comment lists in a page. How do I implement this with a view? – SGhosh Feb 16 '13 at 10:50
  • load the view in the template of the answer content type, and pass the answer node as context – rémy Feb 16 '13 at 19:07
  • ok..so printing the view in my comments-wrapper tpl using views_embed_views is working, but ajax doesn't seem to take effect. drupal.org/node/928882 here it says that the scripts variable in page.tpl.php needs to be redefined. But I am embedding the view in comments-wrapper tpl, so how do I solve this? – SGhosh Feb 18 '13 at 5:17
  • 1
    it seems to be missing the JS that views adds. you have to add them manually. so in you template.php - add function YOURTHEME_preprocess_page(&$vars, $hook) { //Reload the javascript into the scripts. $vars['scripts'] = drupal_get_js(); } - may be even better to check the $vars if you're on the desired content type – rémy Feb 18 '13 at 9:17
  • tried that, didn't work. Actually I am embedding my views in comments-wrapper preprocess, could it be redefining and embedding views must be done in the same preprocess function? – SGhosh Feb 18 '13 at 9:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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