get "Custom Class" inside block view

Permalink
Hi,
Is it possible to get get "Custom Class" or "Custom ID" inside block view via an api?

shahroq
 
hutman replied on at Permalink Reply
hutman
Can you give more detail about where this would be coming from or what you're going to do with it?
shahroq replied on at Permalink Reply
shahroq
On "Edit Mode": Click on "Design & Custom Template", then click on "cog" icon, there are two textarea, "Custom Class" & "Custom ID". These values add to block wrapper DIV. I wonder if it's possible to get these values inside block view.
Gondwana replied on at Permalink Reply
Gondwana
You could get the class and ID by using JS to inspect the DOM. Such an approach may be risky because there's no guarantee that c5 will produce the same DOM structure in future versions. It would be safer to get the values via c5's API or, failing that, c5's database, but I wouldn't know how to do those things.
shahroq replied on at Permalink Reply
shahroq
Any idea on this? Via api?
Gondwana replied on at Permalink Reply
Gondwana
MrKDilkington replied on at Permalink Best Answer Reply
MrKDilkington
Hi shahroq,

I was only able to get this to work by getting a specific named block. When I tried to get a block by ID, getCustomStyle() always returned null.
$block = new Block();
$blockObject = $block->getByName('my_named_block');
if ($blockObject) {
    $styleObject = $blockObject->getCustomStyle();
    if ($styleObject) {
        $styleSetObject = $styleObject->getStyleSet();
        $customClass = $styleSetObject->getCustomClass();
    }
}

The $customClass variable will be a string of any custom classes.
shahroq replied on at Permalink Reply
shahroq
Hi karl,
I want it inside block view.php. ( block template ), so i changed it to:
$customClass = '';
$styleObject = $this->block->getCustomStyle();
if ($styleObject) {
    $styleSetObject = $styleObject->getStyleSet();
    $customClass = $styleSetObject->getCustomClass();
}

Thank you very much for the answer,
Cheers,