Last active
March 5, 2018 15:52
-
-
Save hissy/6255509 to your computer and use it in GitHub Desktop.
[concrete5] Render the hard coded select attribute options list
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 | |
$navigation = Loader::helper('navigation'); | |
$c = Page::getCurrentPage(); | |
// get the attribute key by handle | |
$ak = CollectionAttributeKey::getByHandle('your_attribute_handle'); | |
// get the attribute type controller | |
$atc = $ak->getController(); | |
// check if the attibure type is select | |
if ($atc instanceOf SelectAttributeTypeController) { | |
// get the SelectAttributeTypeOptionList object | |
$optionList = $atc->getOptions(); | |
// check options count | |
if ($optionList->count() > 0) { | |
echo '<ul>'; | |
// get the array of SelectAttributeTypeOption object | |
$options = $optionList->getOptions(); | |
// get the id of selected options | |
$selectedOptions = $atc->request('atSelectOptionID'); | |
if (!is_array($selectedOptions)) { | |
$selectedOptions = array(); | |
} | |
foreach ($options as $option) { | |
$selected = ''; | |
if (in_array($option->getSelectAttributeOptionID(), $selectedOptions)) { | |
$selected = ' class="selected"'; | |
} | |
echo sprintf( | |
'<li%s><a href="%s">%s</a></li>', | |
$selected, | |
$navigation->getLinkToCollection($c) . '?' . $atc->field('atSelectOptionID') . '[]=' . $option->getSelectAttributeOptionID(), | |
$option->getSelectAttributeOptionValue() | |
); | |
} | |
echo '</ul>'; | |
} | |
} | |
?> |
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 | |
$ak = CollectionAttributeKey::getByHandle('your_attribute_handle'); | |
$ak->render('search'); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment