AttributeKeyName and $controller->getTitle()

Permalink
Hi,

So, I am trying to make a better template for concrete/blocks/page_attribute_display/view.php

Right now, title and content are being outputed as '$controller->getTitle()' and '$controller->getContent()' but these output an attribute title 'Title: ' (with a white space after) and content is a bunch of attributes selected, so no way to translate them before we clean a little bit the markup.

I've come up with a 'hack':
concrete/blocks/page_attribute_display/controller.php:
/**
     * Returns the title text to display in front of the value.
     *
     * @return string
     */
    public function getTitleValue()
    {
      return (rtrim($this->getTitle(),': '));
    }


concrete/blocks/page_attribute_display/view.php:
echo $controller->getOpenTag();
if ($controller->getTitle()) {
  echo '<span class="ccm-block-page-attribute-display-title">' . tc('AttributeKeyName', $controller->getTitleValue() ) . ':</span>';
}

for Title attribute, but the content eludes me. How can I retrieve it's content as an array?

View Replies:
hutman replied on at Permalink Reply
hutman
One way you could do this would be to add an elseif into the default case of the switch in the getContent method in the controller to check and see if you have an OptionList and then loop over it to do whatever you want with the options. My example outputs them as a comma delimited list.

} elseif(is_object($content) && $content instanceof \Concrete\Attribute\Select\OptionList){
    $contentString = '';
    foreach($content as $item){
        if(strlen($contentString)){
            $contentString .= ', '.$item->value;
        } else {
            $contentString = $item->value;
        }
    }
    $content = $contentString;