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?
Is it possible to get get "Custom Class" or "Custom ID" inside block view via an api?
Can you give more detail about where this would be coming from or what you're going to do with it?
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.
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.
Any idea on this? Via api?
These might help (or not):
https://documentation.concrete5.org/api/class-Concrete.Core.Block.Bl... (search for customStyle)
https://documentation.concrete5.org/api/class-Concrete.Core.Block.Cu...
https://documentation.concrete5.org/api/class-Concrete.Core.Block.Co...
https://documentation.concrete5.org/api/class-Concrete.Core.Block.Bl... (search for customStyle)
https://documentation.concrete5.org/api/class-Concrete.Core.Block.Cu...
https://documentation.concrete5.org/api/class-Concrete.Core.Block.Co...
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.
The $customClass variable will be a string of any custom classes.
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.
Hi karl,
I want it inside block view.php. ( block template ), so i changed it to:
Thank you very much for the answer,
Cheers,
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,