0

I am using a View in two different pages: page--front.tpl.php and views-view-grid--inside--page-1.tpl.php which is a custom display of a view.

This is the code that is used in both of these

print views_embed_view("loadcover","block",$nid);

and I also set Use AJAX:Yes in the Views settings. The problem is the View's Ajax paging works in the page--front.tpl.php but it's Ajax paging doesn't work in views-view-grid--inside--page-1.tpl.php, In this page the pager is appeared as a link not ajax. What is the problem?


UPDATE:

I tried

print views_embed_view("loadcover","block",$nid);

in page.tpl.php and it worked with Ajax, Is there any problem with Views template files?

I found Disabled AJAX paging with embedded views when used in page.tpl.php it gave me some clues but still I'm unable to solve the problem.


UPDATE:

This is the complete code, This code is exactly the code that is works in page--front.tpl.php. I moved the print views_embed_view("loadcover","block",$nid); in different places of this code but it didn't work again. I guess the problem might be because of js codes that are not loaded in this page.

<?php
global $base_url;
global $language;
$menu  = new stdClass();
$menu = buildMenuObject($menu);
$bookCounter = 0;
while ($bookCounter < sizeof($view->result)){
    $nid = $view->result[$bookCounter++]->nid;
    if($bookCounter <= 6)
    {
        $top = 222 + (188 * floor($bookCounter/7));
    }
    else 
        $top = 252 + (188 * floor($bookCounter/7));
    $node = node_load($nid);
    $wrapper = entity_metadata_wrapper('node',$node);
    $title = $wrapper->title->value();
    $detail = $wrapper->field_detail->value();
    $writer = $wrapper->field_writer->value();
    $edition = $wrapper->field_edition->value();
    $translators = $wrapper->field_translators->value();
    $publisher = $wrapper->field_publisher->value();
    $year = $wrapper->field_year->value();
    $nop = $wrapper->field_nop->value();
    $jelds = $wrapper->field_jeld->value();
    print "<div style='top:".$top."px' class='lib-td-detail lib-td-detail-counter-$bookCounter library-td-detail-nid-".$nid."'>";
        print "<img class='lib-detail-close' src='".$base_url."/sites/all/themes/lib/images/cross.png' />";
        print "<div class='library-fields-container lib-inside-fields-$nid'>";
            print "<div class='library-fields-right library-fields'>";
                print "<div class='library-title'>";
                    print $title;
                print "</div>";
                print "<div class='library-field library-writer'>";
                    print $menu->writer." : ". $writer;
                print "</div>";
                print "<div class='library-field library-edition'>";
                    print $menu->edition." : ". $edition;
                print "</div>";
                print "<div class='library-field library-translators'>";
                    print $menu->translators." : ". $translators;
                print "</div>";
                print "<div class='library-field library-publisher'>";
                    print $menu->publisher." : ". $publisher;
                print "</div>";
                print "<div class='library-f-detail'>";
                    print $detail;
                print "</div>";
            print "</div>";
            print "<div class='library-fields-left library-fields'>";
                print "<div class='library-fields-left-top library-fields-top'>";
                    print views_embed_view("loadcover","block",$nid);
                print "</div>";
                print "<div class='library-fields-left-bottom library-fields-bottom'>";print "</div>";
            print "</div>";
        print "</div>"; 
    print "</div>"; 
} 

?>
4
  • maybe the JS gets confused inside other view-dom-elements. try to print it in a different location in views-view-grid--inside--page-1.tpl.php. do you have a JS error in the console ?
    – rémy
    Jun 17, 2015 at 9:59
  • No there is no js error in console.
    – M a m a D
    Jun 17, 2015 at 18:30
  • have you tried to move the print views_embed out of the div's from the other view ?
    – rémy
    Jun 18, 2015 at 11:56
  • @rémy I updated the question.
    – M a m a D
    Jun 18, 2015 at 12:18

2 Answers 2

1
+50

It looks like you are adding some chunks of code logic to your theme templates? This is not usually recommended in a drupal instance. Have you tried adding a context to include your loadcover view block on the view generating your grid, so that you do not need to print embed in the tpl? https://www.drupal.org/project/context

Enable the module and go to /admin/structure/context/add Set the name of this context, something like Book Grid Display. We use a "Layout" tag group for things like this, but you could use "custom" or just about anything you want, it is optional. Under the Conditions dropdown select Views, and on the list that appears to the right check the box in front of your Inside grid view. Under Reactions select Block. The theme regions will appear as well as the different groupings of blocks available on your system. The last grouping is Views, select your Loadcover view and click the +Add on the theme region you are wanting (I assume Content since you were printing this in the content template).

The page content will have a weight of 0, and the drag-and-drop reorder likes to start at weight -10 so use the Show Row Weights to get it under the view grid if desired. Or at least that is a quirk I have seen when using this method.

Another note, the views_field_view that was mentioned in a comment would allow you to add your Loadcover view as a field in your book grid view, so that you did not have to inject it with custom code from the theme logic layer. If you were wanting to invoke LoadCover for each cell in your grid and I missed that part, then yes views_field_view would solve the problem for you instead of this context solution which will get you one instance of Loadcover.

1
  • Thanks a lot, I will test both solutions and let you know the result. I have never worked with context module. Whether views field module works or not, I will also try context module for learning.
    – M a m a D
    Jun 22, 2015 at 20:50
0

you can try adding the javascript code with views_add_js

views_add_js('ajax');
4
  • The ajax.js is already loaded but after adding your code in the views-view-grid--inside--page-1.tpl.php the js console reported this error: TypeError: settings.views.ajax is undefined: var dialog_area = $(settings.views.ajax.popup, context);
    – M a m a D
    Jun 20, 2015 at 4:44
  • 1
    seems like settings missing, i still believe it confuses having two views, another try could be to add the view via views_field_view
    – rémy
    Jun 20, 2015 at 20:30
  • This module adds a view as a field to another view. How does this solve the problem ?
    – M a m a D
    Jun 22, 2015 at 3:23
  • yes - exactly, try to add your embedded view (loadcover) as a field to your other view. (from which you posted the template code)
    – rémy
    Jun 23, 2015 at 7:30

Your Answer

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

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