View.php problem (need 2 different view.php files)
Permalink
I have a Members Only section which has a completely different menu from my main site. The Members Only section uses the Discussion add-on which utilizes view.php and was therefore grabbing the wrong menu. I was able to fix this by copying discussion.php into my theme and hard-coding the top menu into discussion.php, but for Profiles what can I do? Profiles are tied to the core, so no matter what, if someone clicks a Discussion user, it's going to jump to the Profile and grab the view.php template. So, all of a sudden, when anyone views a Profile from the Discussion board the menu at the top is going to change and they're going to be totally confused.
Two options I can think of (there might be more I don't know about -- hopefully others answer as well):
1) I think you can just add a template file to your theme directory that has the exact name of the single_page to completely override the view.php template. This is a little wonky though because it only matches the last portion of the url -- so if you're wanting to override the "http://domain.com/profile/edit" page, you would add a new "edit.php" file (not "profile.php"). Kind of weird because this has the chance of being accidentally picked up by another page called "edit" that is under a different path. But might work for your situation if used sparingly.
2) Add an "if" statement to your view.php file. Use the handy View::section() function, for example:
Both methods have their warts -- I wish there was a more elegant way to handle multiple view templates for a theme, but they'll get the job done.
-Jordan
1) I think you can just add a template file to your theme directory that has the exact name of the single_page to completely override the view.php template. This is a little wonky though because it only matches the last portion of the url -- so if you're wanting to override the "http://domain.com/profile/edit" page, you would add a new "edit.php" file (not "profile.php"). Kind of weird because this has the chance of being accidentally picked up by another page called "edit" that is under a different path. But might work for your situation if used sparingly.
2) Add an "if" statement to your view.php file. Use the handy View::section() function, for example:
<?php if (View::section('profile')): ?> <!-- put your profile template stuff here --> <?php else: ?> <!-- put your default view template here for everything other than profile pages --> <?php endif; ?>
Both methods have their warts -- I wish there was a more elegant way to handle multiple view templates for a theme, but they'll get the job done.
-Jordan
Thank you, #2 worked perfectly! Man, you really are a life-saver!
For anyone else who may run into this, using jordanlev's solution (#2), this is how I hard-coded two different top menu navigations into the view.php template:
For anyone else who may run into this, using jordanlev's solution (#2), this is how I hard-coded two different top menu navigations into the view.php template:
<div id="nav"> <?php if (View::section('profile')): ?> <?php // Members Only Top Navigation $bt_main =BlockType::getByHandle('autonav'); $bt_main->controller->displayPages = 'custom'; //need to get subpages of Members Area CID $bt_main->controller->orderBy ='display_asc'; $bt_main->controller->displaySubPages ='none'; $bt_main->controller->displayPagesCID = '116'; //Members Area CID $bt_main->render('templates/header_menu'); ?> <?php else: ?> <?php // Regular Top Navigation $bt_main =BlockType::getByHandle('autonav'); $bt_main->controller->displayPages = 'top'; $bt_main->controller->orderBy ='display_asc';
Viewing 15 lines of 20 lines. View entire code block.
How can I make a special Profile page that overrides the tendency to grab view.php?
I looked at the Profile directory and it is not easy to comprehend.