Skip to content

Instantly share code, notes, and snippets.

@zeelot
Created March 27, 2012 04:17
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zeelot/2212507 to your computer and use it in GitHub Desktop.
Save zeelot/2212507 to your computer and use it in GitHub Desktop.
Top navigation with selected status (change dashes for slashes as gists do not allow directories)
<?php
Class View_Page_Browse extends View_Page {
// On this page, 'browse' tab is selected
protected $_selected_top_nav_item = 'browse';
}
<?php
Class View_Page_Home extends View_Page {
// On this page, 'home' tab is selected
protected $_selected_top_nav_item = 'home';
}
<?php
Class View_Page extends Kostache {
// Decides which nav item is selected
protected $_selected_top_nav_item;
public function top_nav()
{
// Return the nav array with url and selected status
return array(
array(
'url' => Route::url('home', ...), // Generate the url using reverse routing
'text' => 'Home',
'selected' => $this->_selected_top_nav_item === 'home',
),
array(
'url' => Route::url('browse', ...), // Generate the url using reverse routing
'text' => 'Browse',
'selected' => $this->_selected_top_nav_item === 'browse',
),
);
}
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
</head>
<body>
<ul class="top-nav">
{{#top_nav}}
<li{{#selected}} class="selected"{{/selected}}><a href="{{url}}">{{text}}</a></li>
{{/top_nav}}
</ul>
<h1>{{title}}</h1>
<p>{{>content}}</p>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment