2

I want to set Omega4 Layout defaults based on Content Type. I am trying to use the following code, but the hook_omega_layout_alter doesn't seem to use the $node variable. What am I missing?

I have already referenced Omega override simple-layout.tpl.php for content types but, once I try and and a switch statement based of $node->type it stops working.

What can I do to set the default Omega4 Layout based on Content Type using the hook_omega_layout_alter function?

function THEME_omega_layout_alter(&$vars, &$layout) {
  $node = $vars['node'];
  switch ($node->type) {
    case "article":
        $layout = 'article';
        break;
    case "blog":
        $layout = 'blog';
        break;
    case "market":
        $layout = 'market';
        break;
    case "merchant":
        $layout = 'merchant';
        break;
    case "product":
        $layout = 'product';
        break;
    case "update":
        $layout = 'update';
        break;
  }

}

2 Answers 2

1

So this works for me...

function THEME_omega_layout_alter(&$layout) {

  $default = 'basic';

  $layout = $default;

  if (arg(0) == 'node' && is_numeric(arg(1))) {
    $nid = arg(1);
    $node = node_load($nid);
    if (isset($node) && $node->type == 'page') {
      $layout = 'basic';
    }
    if (isset($node) && ($node->type == 'project_page' || $node->type == 'project_front')) {
      $layout = 'full-page';
    }
  }
}

Hope that helps someone. I personally think it is overkill to have to create new layouts in omega 4 to create minor changes... but hey, it is a quick and simple process!

1

As per referenced question I would go with something like the following:

function THEMENAME_omega_layout_alter(&$layout) {
  if (arg(0) == 'node' && is_numeric(arg(1))
      && $node = node_load(arg(1))) {
        switch ($node->type) {
          case 'article':
            $layout = 'article';
            break;
          case 'blog':
            $layout = 'blog';
            break;
          default:
            $layout = 'default';
        }
   }
}

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.