Created
January 9, 2014 11:31
-
-
Save danielchikaka/8332760 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// include this file in app/start/global.php | |
View::creator('menu', 'MenuCreator'); | |
View::composer('menu', 'MyMenuComposer'); | |
// you can add as many composers to the same view as you like | |
View::composer('menu', 'MyOtherMenuComposer'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// include this file in app/start/global.php | |
HTML::macro('menuItem', function($item) | |
{ | |
if (!empty($item['subitems'])) { | |
return '<li>' . HTML::menu($item['subitems']) . '</li>'; | |
} | |
if (!empty($item['url'])) { | |
$url = URL::to($item['url']); | |
} elseif (!empty($item['route'])) { | |
$url = URL::route($item['route']); | |
} elseif (!empty($item['action'])) { | |
$url = URL::action($item['action']); | |
} | |
if (isset($url)) { | |
return '<li>' . HTML::link($item['title'], $url) . '</li>'; | |
} else { | |
return '<li>' . HTML::entities($item['title']) . '</li>'; | |
} | |
}); | |
HTML::macro('menu', function($items) | |
{ | |
$html = '<ul>'; | |
foreach ($items as $item) { | |
$html .= HTML::menuItem($item); | |
} | |
$html .= '</ul>'; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment