What I tried to do is load a node which embeds (views_embed_view()) an Ajax enabled view (Sorting + paging). When viewing the node itself the view works, but loading the node asynchronous and attaching the behaviors for the new part, the ajax sorting does not work. After some investigation, I found out that the Javascript Settings for the Ajax Views are added in function template_preprocess_views_view(&$vars) in theme.inc but it does not get called in that case and so the behaviors are not attached in ajax_view.js:
if (Drupal.settings && Drupal.settings.views && Drupal.settings.views.ajaxViews) {
$.each(Drupal.settings.views.ajaxViews, function(i, settings) {
// @todo: Figure out where to store the object.
new Drupal.views.ajaxView(settings);
});
}
Is that the problem?
Any ideas?
Comments
Comment #1
chichilatte commentedI'm on Drupal 6.22 & Views 6.x-3.0+67-dev, but I had something very similar trying to views_embed_view() an ajax-enabled view inside a template. After a good few hours debugging, it turns out the ajax javascript isn't loading in the header (i suppose understandably, since we're printing the view manually). I managed to fix it by adding the external js files myself in the header, and inserting the required "settings" javascript immediately after the view is printed in the template.
So in my template.tpl.php file i put:
And to add the settings javascript after the embedded view had been printed i added this in the page template itself:
Works for me so far, even with a solr search box, cool!
NOTE: If you ever want to debug this kind of thing successfully, i sohh recommend using a combination of the Netbeans debugger, the apache/php xdebug extension and php's xdebug_break() function.
Comment #2
dawehner@chichilatte
So you use views_embed_view in a page.tpl.php? The problem why this simply can't work is because $scripts is already printed out at that moment. Better use hook_preprocess_page and recalc the $vars['scripts'] like you do here.
@krisdigital
I assume you use some manual jquery/php code for that. If you would use the drupal ajax system, it should add you the new ajax settings for you. For more information how to do that, there are some presentations from merlinofchaos available.
Comment #3
chichilatte commentedAh yep i see, just get the view in the preprocess_page hook in yr template.tpl.php, e.g.
And in your template you can just
<?php print $my_view_html; ?>. Ta.Comment #4.0
(not verified) commentedadded details