Accessing Hardcoded Blocks - Blog

Permalink 1 user found helpful
Afternoon All,

If i have a block hard coded into a page type theme file, and i want to make use of the getCommentCountString. However this assumes there's a block attached to an area, whereas I've hard coded it like so:
<?php
    $commentsBT = BlockType::getByHandle('guestbook');
    $commentsBT->controller->requireApproval = 0;
    $commentsBT->controller->title = 'Comments';
    $commentsBT->controller->dateFormat ='M jS, Y';
    $commentsBT->controller->displayGuestBookForm = 1;
    $commentsBT->controller->displayCaptcha = 1;
    $commentsBT->controller->authenticationRequired = 1;
    $commentsBT->controller->notifyEmail = 'email@email.com';
    $commentsBT->render('view');
?>


Is there any way of getting a handle on this block externally? The getCommentCountString heads in via an Area, as shown below, but I don't have an area...!

$c = $this->getCollectionObject();
$a = new Area('Blog Post Footer');
$blocks = $a->getAreaBlocksArray($c);
if(is_array($blocks) && count($blocks) > 0) {
        foreach($blocks as $b) {
                if($b->getBlockTypeHandle() == 'guestbook') {

ggn06awu
 
ggn06awu replied on at Permalink Best Answer Reply
ggn06awu
For those that reach this looking for a similar answer...

The basically isn't a way to do this, as the block isn't known by the database necessarily, just the theme file it was coded into. I decided to set up page defaults so that the guestblock was set to be added by default on these page types, and then recreated (re-imported) all the pages it affected. Permissions were used to lock it down from there.