I made my own theme, Better Message won't work, but when I changed to Drupal default theme, it worked. What should I do?

Comments

YK85’s picture

Same problem here. Did you resolve your issue?

houen’s picture

Bump - samme issue. Anyone got a fix? Im using a custom tailored sub-theme of Zen...

amfis’s picture

Neither do I see messages using my custom theme.

houen’s picture

Bump

nikita petrov’s picture

Ok, i've found the solution, but it required one module's hack:

1. add to you'r theme hook _theme() and paste this:

function yourtheme_theme()
{
  return array(
    'status_messages' => array(
      'arguments' => array('display' => NULL),
	),
  );
}

If you using zen_starter_kit theme like me, you'r _theme function will look like this:

function yourtheme_theme(&$existing, $type, $theme, $path) {
  $hooks = zen_theme($existing, $type, $theme, $path);
  $hooks['status_messages'] = array(
      'arguments' => array('display' => NULL),
	);  
  return $hooks;
}

2. Copy and paste function "theme_better_messages" from file "better_messages.module" (line 56) into you'r theme and rename it to youtheme_status_messages (note: yourtheme_STATUS_messages, not "better"!)

3. Instert following line into this function
$_SESSION['better_messages_hack'] = $output;
so you you'r function must be like this:

function YOURTHEME_status_messages($display = NULL) {
	$output = '';
	$better_messages = better_messages_process_visibility();
 	$access = user_access('access better messages');
	$message = drupal_get_messages($display, false);
	if ($better_messages && $access && !empty($message)) {
		$disable_autoclose = array_key_exists('error', $message);
		better_messages_add_files($disable_autoclose);
		$message = theme('better_messages_content', $display);
		// We save the intial output to SESSION so we can put it in <noscript> on page_preprocess
		$_SESSION['original_messages'] = $message;
		$message_skin = theme('better_messages', $message);
		// We add a special ID so that JavaScript knows what to handle. Changing the ID will break JavaScript handling code.
		$output = "<div id=\"better-messages-wrapper\" style=\"display:none;overflow:visible;position:absolute;z-index:9999;\">\n". 
					$message_skin ."\n</div>\n";
	}
	else { $output = theme('better_messages_content', $display); }
	$_SESSION['better_messages_hack'] = $output;
	return $output;
}

4. In you'r theme's template.php into hook _preprocess_page insert following lines:

function YOURTHEME_preprocess_page(&$vars, $hook) { 
  $vars['messages'] = $_SESSION['better_messages_hack'];
  unset($_SESSION['better_messages_hack']);
}

5. In you'r page.tpl.php print messages by command
print $messages;

6. After all, you must hack file better_messages.module and comment line 53 :
//$theme_registry['status_messages']['function'] = "theme_better_messages";

7. Click on "save" button in /admin/build/themes and clear cache.

Enjoy! :)

Sk8erPeter’s picture

It's really interesting, I can NOT confirm that. I'm also using Better Messages 6.x-1.13 with an own subtheme of Zen theme, but everything seems to work!

Didn't you forget to set the correct permissions? They should be set like I wrote here.

hunteryxx’s picture

I was stuck for a while. The solution is to make sure your page.tpl.php includes print $closure;

chinita7’s picture

My template file has print $closure; but it still doesn't work and the messages are displayed at the bottom of the page (not popped up).

bucefal91’s picture

Issue summary: View changes
Status: Active » Closed (outdated)

The version 6.x is no longer supported.