Last active
August 29, 2015 13:57
-
-
Save hissy/9697627 to your computer and use it in GitHub Desktop.
#concrete5 #DesignerContentPro Manual Nav block made with Designer Content Pro ("Combo" Link field, additional option field)
This file contains 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 defined('C5_EXECUTE') or die(_("Access Denied.")); ?> | |
<?php /* This block was made with Designer Content Pro. Visit http://theblockery.com/dcp for documentation. */ ?> | |
<?php | |
/** | |
* link: Link Field | |
* css_class: Textbox field | |
*/ | |
// Get current page path | |
$current_path = Page::getCurrentPage()->getCollectionPath(); | |
// Get repeating items | |
$items = $controller->getRepeatingItems(); | |
// Check if items exist | |
if (count($items) > 0) : ?> | |
<nav class="dcp-manual-nav" role="navigation"> | |
<ul> | |
<?php foreach ($items as $item): | |
// Get field values | |
$title = $item->link->getText(); | |
$url = $item->link->getHref(); | |
// Determine CSS classes | |
$classes = array(); | |
// Check if the link is c5 Page | |
if ($item->link->isPageLink()){ | |
$page = $item->link->getPageObj(); // to get page object, you need DCP 1.2+ | |
$target = ($page->getCollectionPointerExternalLink() != '' && $page->openCollectionPointerExternalLinkInNewWindow()) ? '_blank' : $page->getAttribute('nav_target'); | |
$target = empty($target) ? '_self' : $target; | |
// get the nav menu item's path (for comparison to the current page path) | |
$item_path = $item->link->getPageObj()->getCollectionPath(); | |
if ($item_path == $current_path) { | |
// class for the page currently being viewed | |
$classes[] = 'nav-selected'; | |
} | |
if (!empty($item_path) && (strpos($current_path, $item_path) === 0)) { | |
// class for parent items of the page currently being viewed (except the home page) | |
$classes[] = 'nav-path-selected'; | |
} | |
} else { | |
// the link is external link | |
$target = '_blank'; | |
} | |
if ($item->css_class->getText()) { | |
// class from the item field | |
$classes[] = $item->css_class->getText(); | |
} | |
// Put all classes together into one space-separated string | |
$class = implode(" ", $classes); | |
?> | |
<li><a href="<?php echo $url?>" class="<?php echo $class?>" target="<?php echo $target?>"><?php echo $title?></a></li> | |
<?php endforeach; ?> | |
</ul> | |
</nav> | |
<?php endif; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Updated to simplify version. Thanks Jordan!
http://www.concrete5.org/marketplace/addons/designer-content-pro/forums/view-template-example-manual-nav-with-combo-link-field/