Closed (fixed)
Project:
Views (for Drupal 7)
Version:
6.x-2.11
Component:
Miscellaneous
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
28 Feb 2009 at 01:17 UTC
Updated:
5 Dec 2012 at 20:17 UTC
Right now this is my code:
$view = views_get_view('listing_comments');
print $view->preview();
using preview() does preserve paging, but it does not enable ajax paging. What is the correct approach to printing a view in a template file with ajax paging enabled?
Comments
Comment #1
dawehneruse can use this
where page_1 is your display id
Comment #2
jannalexx commentedprint views_embed_view('yourview', 'page_1', $args);
same issue here
print views_embed_view does not enable ajax paging, is that true?
same view as a block or panel has ajax paging enabled in the same page (front page)..
using print views_embed_view in page-front.tpl.php does not enable ajax paging in those embedded views.
Any ideas?
Comment #3
jannalexx commentedupdate
node.tpl.php is OK
we can have ajax paging with print views_embed_view
using it in..
page.tpl.php (or page-front.tpl.php) ajax paging is disabled
has anyone experienced this issue?
Comment #4
dawehnerthis is clear!
because $scripts is build there.
use the preprocess_page to add the output and add $vars['scripts'] = drupal_get_js(); at the end of the preprocess_page function
Comment #5
jannalexx commentedvery well, in template.php (at the end)
thats it, thanks
Comment #7
TimG1 commentedI'm using Views 6.x-2.11 is there something different I have to do for this version?
I have a page.tpl.php file that I'm trying to embed a view on...
print views_embed_view('Stories','block_2', $arg);I've tried adding
$vars['scripts'] = drupal_get_js();like this......in my template.php. I'm still not getting any ajaxy paging. Am I missing something?
Thanks for reading,
-Tim
Comment #8
merlinofchaos commentedBy doing this in page.tpl.php the problem is that the $scripts variable has already rendered, and so no new javascript is being output.
You could move the code to template.php, put it in your THEMENAME_preprocess_page() and stick it in a variable. Then, after, you've run your embed, you could reset the $scripts value (see template_preprocess_page() for the precise code that sets that up. I thikn it's just drupal_get_js()).
Comment #9
TimG1 commentedAh ha! Moving the view embed to the template.php was the piece I was missing, thanks!
Here's what my template_preprocess_page in my template.php looks like now...
Then in page.tpl.php print out view_stories...
Thanks again!
-Tim
Comment #11
mag2000 commentedThe following code is running and i do not have the ajax problem as well. But when i use the same code in the page which having the form for user to enter the company name and date selection and then view display on the screen. It display fine, but when i click the next button it is not working.The reason is that page button have the url like following. Any body have the clue.
?q=node/45&page=1&selcomp=abc&dfrom=2001/01/01&dto=2002/0/01&submit=submit1;
instead of
?q=node/45&page=1;
Code :
Comment #12
mag2000 commentedI moved the value of user selection to session variable and those pass to view and now it is working...
Comment #13
stefan81 commentedHi merlinofchaos,
Thank you for your explanation at #8, it work out!
An other performance related question:
By moving the views_embed_view to template.php, is the view executed on every page load, or only when the variable is calling for it?
Comment #14
deadcyclo commentedForget it... I posted in the wrong thread.
Comment #15
fourmi4x commented@stefan, if you make it conditional, like:
=> it will be loaded only when you want it.
About the general issue, I added something to http://drupalcontrib.org/api/drupal/contributions--views--views.module/f..., because I struggled a lot to track that down, all the more since I was investigating the problem because of the exposed filters and not the pager. But maybe this should be explained somewhere else in the documentation?
Comment #16
karljohann commentedHow would I go about doing this if I wanted to embed a view in a module?