1

I've recently been told to use Panels to dynamically load content into different sections with Drupal. However, I've just realized that there is an easy way to do it, I've added this jQuery code to all menu items:

$('.menu a').click(function(){
    $('#content').load($(this).attr('href') + " #content");
    return false; //to avoid refresh
});

In this way I can easily update anyblock from any link without having to use Panels.

Is this approach a good one ? Do you also think Panels is not necessary to simply load html into website sections dynamically ?

thanks

googletorp
  • 33,075
  • 15
  • 67
  • 82
aneuryzm
  • 63,052
  • 100
  • 273
  • 488

1 Answers1

2

Panels main usage, is not loading content without page loads. It's primarily used

  • to create different page layouts that depends on certain criteria, that you can setup with code, or in the AI.
  • Let the content of the page, be aware of which content is being viewed, and tying to different content together.

Your current script will work, but it's a bit crude in it's current form. Fx, what will happen if a user clicks several times. If you want to dynamically update your content, you should only change the parts that needs changing instead of loading/changing the whole page. Then you might as well just load the new page instead. I guess this is where Panels can help you, but I haven't tried using Panels like that.

googletorp
  • 33,075
  • 15
  • 67
  • 82
  • thanks, so the question here is: how can I *only* load the node content instead of the usual page ? What's the link to a node ? (of course without having to use Panels) thanks – aneuryzm Jul 01 '10 at 13:25
  • @Patrick: ATM, there is not a way to just load the content of a node, but it should be fairly simple to make a module that does this. What makes this a bit more tricky is that not all pages is node views. – googletorp Jul 01 '10 at 13:39
  • I think I've solved. I'm passing a parameter "onlyNode=true" together with the link, and I've updated my template in order to ignore the page content if this variable is true. In this way the selection is done server side and I'm not loading the entire page. – aneuryzm Jul 01 '10 at 18:43
  • yeah indeed, solution is here: http://stackoverflow.com/questions/247991/displaying-a-drupal-view-without-a-page-template-around-it – aneuryzm Jul 02 '10 at 05:37