Page Attribute Display Block custom template to output unordered list (w/ Select attribute type)

I'm using the core Page Attribute Display block (in 5.7 of course) to display a SELECT type attribute (so with multiple values), and I want to output as an Unordered List.

To me this seems like something that would be VERY commonplace. Not only that, but the view file is simple
echo $controller->getOpenTag();
echo "<span class=\"ccm-block-page-attribute-display-title\">".$controller->getTitle()."</span>";
echo $controller->getContent();
echo $controller->getCloseTag();

So I'm wondering if anyone has already done it.

I can see the attributes themselves are output by just the one line
echo $controller->getContent();

and I see that it outputs the data as each item as a new line.
So a little php magic to put it back into an array, and then loop through and output it as needed...

View Replies:
WillemAnchor replied on at Permalink Reply
getContent() calls $c->getAttribute()
if (!is_scalar($content) && (!is_object($content) || !method_exists($content, '__toString'))) {
                        $content = $c->getAttribute($this->attributeHandle, 'displaySanitized');

getAttribute can be found in src/page/collection/collection.php and has some nice remarks.
* $displayMode makes it possible to get the correct output
     * value. When you need the raw attribute value or object, use
     * this:
     * <code>
     * $c = Page::getCurrentPage();
     * $attributeValue = $c->getAttribute('attribute_handle');
     * </code>

Now let's take a look at the select attribute...there is no value.php but the controller has a getValue, which calls getSelectedOptions().
This will return an OptionList object...that you can use in your view.php. (see \concrete\attribute\select\optionlist)

have fun :D
OKDnet replied on at Permalink Reply
Actually it turned out pretty simple.
This works like a charm
$itemsraw = trim($controller->getContent());
$itemsarray = explode("\n", $itemsraw);
if (!empty($itemsarray)) {
    foreach ($itemsarray as $item){
    echo "<li>" . $item . "</li>";

I'm sure somebody will find this useful.