Skip to content

Instantly share code, notes, and snippets.

@hissy hissy/view.php
Last active Aug 29, 2015

Embed
What would you like to do?
#concrete5 #DesignerContentPro Manual Nav block made with Designer Content Pro ("Combo" Link field, additional option field)
<?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;
@hissy

This comment has been minimized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.