views:

43

answers:

1

hi,

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

+1  A: 

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
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
Patrick
@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
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.
Patrick
yeah indeed, solution is here: http://stackoverflow.com/questions/247991/displaying-a-drupal-view-without-a-page-template-around-it
Patrick