Skip to content

Instantly share code, notes, and snippets.

@hissy
Last active March 5, 2018 15:52
Show Gist options
  • Save hissy/6255509 to your computer and use it in GitHub Desktop.
Save hissy/6255509 to your computer and use it in GitHub Desktop.
[concrete5] Render the hard coded select attribute options list
<?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>';
}
}
?>
<?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