Skip to content
Snippets Groups Projects
Commit 244f70d9 authored by Demian Katz's avatar Demian Katz
Browse files

Make template context available to view for proper jquerymobile menu generation.

parent 87a7b413
No related merge requests found
...@@ -65,6 +65,7 @@ class Bootstrap ...@@ -65,6 +65,7 @@ class Bootstrap
public function bootstrap() public function bootstrap()
{ {
$this->initAccount(); $this->initAccount();
$this->initContext();
$this->initTheme(); $this->initTheme();
} }
...@@ -83,6 +84,29 @@ class Bootstrap ...@@ -83,6 +84,29 @@ class Bootstrap
$this->events->attach('dispatch', $callback); $this->events->attach('dispatch', $callback);
} }
/**
* Set view variables representing the current context.
*
* @return void
*/
protected function initContext()
{
$callback = function($event) {
$serviceManager = $event->getApplication()->getServiceManager();
$viewModel = $serviceManager->get('viewmanager')->getViewModel();
// Grab the template name from the first child -- we can use this to
// figure out the current template context.
$children = $viewModel->getChildren();
$parts = explode('/', $children[0]->getTemplate());
$viewModel->setVariable('templateDir', $parts[0]);
$viewModel->setVariable(
'templateName', isset($parts[1]) ? $parts[1] : null
);
};
$this->events->attach('dispatch', $callback);
}
/** /**
* Set up theme handling. * Set up theme handling.
* *
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
<? <?
// if a module has footer-navbar.tpl, then use it, otherwise use default // if a module has footer-navbar.tpl, then use it, otherwise use default
try { try {
echo $this->render("{$this->controller}/footer-navbar.phtml"); echo $this->render("{$this->layout()->templateDir}/footer-navbar.phtml");
} catch (\Zend\View\Exception\RuntimeException $e) { } catch (\Zend\View\Exception\RuntimeException $e) {
// no module-specific footer navbar found -- use default. // no module-specific footer navbar found -- use default.
echo $this->render('default-footer-navbar.phtml'); echo $this->render('default-footer-navbar.phtml');
......
...@@ -20,10 +20,10 @@ ...@@ -20,10 +20,10 @@
<? <?
// if a module has header-navbar.tpl, then use it // if a module has header-navbar.tpl, then use it
try { try {
echo $this->render("{$this->controller}/header-navbar.phtml"); echo $this->render("{$this->layout()->templateDir}/header-navbar.phtml");
} catch (\Zend\View\Exception\RuntimeException $e) { } catch (\Zend\View\Exception\RuntimeException $e) {
// if this is a record view, load the record header; otherwise, do nothing: // if this is a record view, load the record header; otherwise, do nothing:
if (substr($this->controller, -6) == 'record') { if (substr($this->layout()->templateDir, -6) == 'record') {
echo $this->render('record/header-navbar.phtml'); echo $this->render('record/header-navbar.phtml');
} }
} }
......
<? if ($this->layout()->account->isLoggedIn()): ?> <? if ($this->layout()->account->isLoggedIn()): ?>
<div data-role="navbar"> <div data-role="navbar">
<ul> <ul>
<li><a rel="external" <?=$this->action=="mylist" ? ' class="ui-btn-active"' : ''?> href="<?=$this->url('myresearch-favorites')?>"><?=$this->transEsc('Favorites')?></a></li> <li><a rel="external" <?=$this->layout()->templateName=="mylist" ? ' class="ui-btn-active"' : ''?> href="<?=$this->url('myresearch-favorites')?>"><?=$this->transEsc('Favorites')?></a></li>
<li><a rel="external" <?=$this->action=="history" ? ' class="ui-btn-active"' : ''?> href="<?=$this->url('search-history')?>?require_login"><?=$this->transEsc('History')?></a></li> <li><a rel="external" <?=$this->layout()->templateName=="history" ? ' class="ui-btn-active"' : ''?> href="<?=$this->url('search-history')?>?require_login"><?=$this->transEsc('History')?></a></li>
<li><a rel="external" href="<?=$this->url('myresearch-logout')?>"><?=$this->transEsc("Log Out")?></a></li> <li><a rel="external" href="<?=$this->url('myresearch-logout')?>"><?=$this->transEsc("Log Out")?></a></li>
</ul> </ul>
</div> </div>
......
<? if (VF_Account_Manager::getInstance()->isLoggedIn()): ?> <? if (VF_Account_Manager::getInstance()->isLoggedIn()): ?>
<div data-role="navbar"> <div data-role="navbar">
<ul> <ul>
<li><a rel="external" <?=$this->action=="checkedout" ? ' class="ui-btn-active"' : ''?> href="<?=$this->url('myresearch-checkedout')?>"><?=$this->transEsc('Checked Out')?></a></li> <li><a rel="external" <?=$this->layout()->templateName=="checkedout" ? ' class="ui-btn-active"' : ''?> href="<?=$this->url('myresearch-checkedout')?>"><?=$this->transEsc('Checked Out')?></a></li>
<li><a rel="external" <?=$this->action=="holds" ? ' class="ui-btn-active"' : ''?> href="<?=$this->url('myresearch-holds')?>"><?=$this->transEsc('Holds')?></a></li> <li><a rel="external" <?=$this->layout()->templateName=="holds" ? ' class="ui-btn-active"' : ''?> href="<?=$this->url('myresearch-holds')?>"><?=$this->transEsc('Holds')?></a></li>
<li><a rel="external" <?=$this->action=="fines" ? ' class="ui-btn-active"' : ''?> href="<?=$this->url('myresearch-fines')?>"><?=$this->transEsc('Fines')?></a></li> <li><a rel="external" <?=$this->layout()->templateName=="fines" ? ' class="ui-btn-active"' : ''?> href="<?=$this->url('myresearch-fines')?>"><?=$this->transEsc('Fines')?></a></li>
</ul> </ul>
</div> </div>
<? endif; ?> <? endif; ?>
\ No newline at end of file
<? if ($this->action == 'history'): // use myresearch navbar for Search/history ?> <? if ($this->layout()->templateName == 'history'): // use myresearch navbar for Search/history ?>
<?=$this->render('myresearch/footer-navbar.phtml')?> <?=$this->render('myresearch/footer-navbar.phtml')?>
<? else: // use default navbar for everything else ?> <? else: // use default navbar for everything else ?>
<?=$this->render('default-footer-navbar.phtml');?> <?=$this->render('default-footer-navbar.phtml');?>
......
<? if ($this->action == 'history'): // use myresearch navbar for Search/history ?> <? if ($this->layout()->templateName == 'history'): // use myresearch navbar for Search/history ?>
<?=$this->render('myresearch/header-navbar.phtml')?> <?=$this->render('myresearch/header-navbar.phtml')?>
<? elseif (isset($this->results) && $this->results->getResultTotal() > 0): ?> <? elseif (isset($this->results) && is_object($this->results) && $this->results->getResultTotal() > 0): ?>
<div data-role="navbar"> <div data-role="navbar">
<ul> <ul>
<li><a href="#Search-narrow" data-rel="dialog" data-transition="flip"><?=$this->transEsc('Narrow Search')?></a></li> <li><a href="#Search-narrow" data-rel="dialog" data-transition="flip"><?=$this->transEsc('Narrow Search')?></a></li>
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment