Question

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

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top