Alternate header.php file in theme's view.php

Permalink
I'm currently using two different elements/header.php files in my theme (header.php and header_users.php for example).
Most of my site uses header.php. The area that needs header_users.php needs a totally different auto-nav as it's a subdomain, so I only want it's nav to show it's child pages and function as a stand-alone site almost for it's "user" audience. This way, they don't have to wade thru the entire site for their specific stuff. It's all right there as a subdomain. Hope that makes sense.
To do this, users.subdomain has it's own page_types (home_users.php and users.php). This calls the alternate header I need and all works well.
Except for the theme's view.php file applied to single_pages. This is particularly hitting me on a blog posting single_page. So I wrote the script below into my themes view.php file to filter for the pages parent page, if it matched my sub domain or sub's blog parent, use the header_user.php else user header.php
global $c;
  $nh = Loader::helper('navigation');
  $cobj = $nh->getTrailToCollection($c);
  $rcobj = array_reverse($cobj);
    if(is_object($rcobj[2])) {
      $pID  = $rcobj[2]->getCollectionID();
     $pID2  = $rcobj[3]->getCollectionID();
      $page = Page::getByID($pID);  
       $page2 = Page::getByID($pID2);
      //Get some page ID's
    $page = $page->getCollectionID();//Or name: $page->getCollectionName();
    $page2 = $page2->getCollectionID();
     if(($page == '3040') OR ($page == '3568')){ /* 3040 == Users , 3568 == Users Blog. Add ID's here as needed. *
         $userPortal = true;
     }else{


This works great. But blows up other single_pages like /login and /members.
Any advice on the best way to do this would be greatly appreciated.
My method seems way to hackish to me, but it kinda works. User Blog does grad the correct header. It's the other single_pages that screw up.
I'm trying to do it this way to avoid making multiple themes. Though I did think about making a second theme instead, but linking all of it's CSS and JS to the main theme's files instead of duplicating them. That method seems more logical and would likely make my current issue a non-issue. I'm just trying to avoid multiple themes, but I'm open to it if that's the advisable solution.
Cheers.

PatrickHenry
 
JohntheFish replied on at Permalink Reply
JohntheFish
At a guess, one of the pages does not exist for the other single pages, so when you get the page, rather than getting and object you get null, then trying to get the ID on that causes an object does not exist error.

Before getting an ID on a page, do an is_object($page) test on it. If it isn't an object, then don't get the ID and you can be sure it isn't the page you want.

If you decide to go the theme route, have a look at Magic Yogurt for an example of cloning the core Greek Yogurt theme (you can ignore the rest of it, the cloning is all you would need)
PatrickHenry replied on at Permalink Reply
PatrickHenry
You know what.
It was hackish. I just stuck with the pattern and broke down and made a new theme. Solved my DRY delima by linking mostly to resources in the main them, and gave it all a little speed bump by moving those shared js and css files out to the root level.
Sub-Theme does link to it's own CSS file tho, and over-rides are accomplished by this way:
<html id="user-theme">.

Works beautifully.
Hope someone else finds this advice useful and marks me as the right answer!