I have a site where I want to share the same main menu accross multiple subdomains, but each subdomain will have a unique start page. The subdomains represent different chapters of an international Christian apologetics ministry.
When I use the One Gateway plugin to switch contexts and changes site start it works fine, but the main menu no longer works. For example, index.php?id=2 which is in a different context (’web’) is not accessible from the context (’UNCC’). I can think of one way to work around this which is simply to prefix all my main-level menu items with the base url of the main site.
So, instead of:
$outputArray['page_link'] = '[[~' . $mainMenuObject->get('id') . ']]';
I would code in the snippet
$outputArray['page_link'] = 'http://www.ratiochristi.org/' . '[[~' . $mainMenuObject->get('id') . ']]';
Is this the best approach to what I’m trying to accomplish?
Here is the main domain:
Ratio Christi
Here is the subdomain:
Ratio Christi - NC State
UPDATE: I tried prefixing all the links with the main domain but the link tags from the web context aren’t getting parsed in the non-web contexts, so:
$outputArray['page_link'] = 'http://www.ratiochristi.org/' . '[[~' . $mainMenuObject->get('id') . ']]';
shows up as
http://www.ratiochristi.org/ instead of
http://www.ratiochristi.org/index.php?id=2 when parsed in the context "NCState"
OK, this works - but I’m not sure if it’s the best approach. Also, at some point I’ll be wanting to switch to friendly URL’s and I’m not sure if this way will mess things up for that:
$outputArray['page_link'] = 'http://www.ratiochristi.org/index.php?id=' . $mainMenuObject->get('id') ;
Here’s the entire snippet:
<?php
$currentPage = $modx->resource->get('id');
$currentPageParents = $modx->getParentIds($currentPage);
$query = $modx->newQuery('modResource');
$query->where(array(
'parent' => 0
,'published' => 1
,'hidemenu' => 0
,'context_key' => 'web'
));
$query->sortby('menuindex, id', 'ASC');
$mainMenuObjects = $modx->getCollection('modResource',$query);
$arrayKeys = array_keys($mainMenuObjects);
foreach($mainMenuObjects as $key => $mainMenuObject){
$outputArray['link_class'] = $currentPage == $mainMenuObject->get('id') ? ' active' : '';
//$outputArray['page_link'] = '[[~' . $mainMenuObject->get('id') . ']]';
//$outputArray['page_link'] = 'http://www.ratiochristi.org/' . '[[~' . $mainMenuObject->get('id') . ']]';
$outputArray['page_link'] = 'http://www.ratiochristi.org/index.php?id=' . $mainMenuObject->get('id') ;
if($outputArray['link_class'] == '') {
$outputArray['link_class'] = in_array($mainMenuObject->get('id'), $currentPageParents) ? ' active' : '';
}
$outputArray['menu_title'] = $mainMenuObject->get('menutitle');
$outputArray['menu_id'] = $mainMenuObject->get('id');
if ($key == $arrayKeys[0]) {
$outputArray['link_class'] .= ' first';
echo $modx->parseChunk('NavFirst', $outputArray);
}
else if ($key != end($arrayKeys)) {
echo $modx->parseChunk('NavRepeat', $outputArray);
}
else {
$outputArray['link_class'] .= ' last';
echo $modx->parseChunk('NavLast', $outputArray);
}
}
?>