1

What I am looking for: I have a custom node link which, when clicked, displays a custom HTML content (option selections) in a lightbox. I need to pass an argument to the HTML content to generate the HTML code.

What I did: I created a menu callback with one argument, and a template file for this "page" that does the processing and display the HTML content in the lightbox. I guess it's a little bit overkill and it takes quite some time for the whole render to be computed.

Would it be better (faster) to override the render with theme function? If that's the preferred solution, how to do? Create a my_theme_page() function in template.php file?

Or can I generate the HTML in the callback function?

Any help would be appreciated.

2
  • Nice question i like the What I did, +1
    – niksmac
    Commented Mar 26, 2013 at 8:23
  • thanks, but it is sounds like too much processing to display simple content in a lightbox. Thanks for the bold as well
    – rsahli
    Commented Mar 26, 2013 at 9:11

1 Answer 1

0

After a lot of googling, I found a nice solution to my problem.

First, one needs to register its menu with callback (in a custom module):

function MY_CUSTOM_MODULE_menu() {
  $items = array();
  $items['my_link_url_path/%'] = array(
    'title' => 'content title', 
    'page callback' => 'MY_PAGE_CALLBACK',
    'page arguments' => array(1),
    'access callback' => TRUE,
    'type' => MENU_CALLBACK,
   );
   return $items;
}

Then the HTML content you want to be in the lightbox has to be printed in the callback function (you can define this function in your custom module file) as follow:

function MY_PAGE_CALLBACK($MY_PASSED_ARGUMENT = NULL) {
  print 'This is my HTML content displayed in the lightbox: Arg = ' . $MY_PASSED_ARGUMENT ; 
}

The trick comes from the fact that you do not return, but print directly the output. No theme layers will be processed.

Just add your link somewhere (with the lightmodal rel attribute if you are using Lightbox2 (http://drupal.org/project/lightbox2):

<a href="/my_link_url_path/345" rel="lightmodal">Click me</a>

This will display 'This is my HTML content displayed in the lightbox: Arg = 345' in a lightbox.

Note: don't forget to empty the cache when changing your menus...

Your Answer

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

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