Ajax for global scrapbooks block is not working?

Permalink 1 user found helpful
Hi All,

I have one issue with the global scrapbook block , before i was having the block on single page where the ajax part with calling the function by using $this->action was working fine but when i added this block in scrapbook then after the part i made is not wroking even the function is also not being call instead it takes full page output so does anyone face this issue or anyone have idea how to deal with ajax when the block is from scrapbook

I found that this issue of ajax is not working is because of the area is not assigned in the case when the block is in the global scrapbook so is there any other way that we can use ajax to call block without area or is there any other way by which i can assign the area to global block?

please help me to get out of this

 
richinnz replied on at Permalink Best Answer Reply
richinnz
Hi Savan
Dont know if you have resolved this issue but I had the same problem so I set-to debugging concrete5 to find the issue.

Assuming I have the same issue as you - I've solved it by doing 2 things.

1. I put the block into my theme using code (rather than paste from scrapbook). However this block needs to be associated directly with the block loaded in the scrapbook. My scrapbook is called mailchimptest and the block I want to load which is in the scrapbook is called mc.

This is the code for the theme page.
//get hold of the scrapbook
$scrapbookHelper=Loader::helper('concrete/scrapbook');
$myc = $scrapbookHelper->getGlobalScrapbookPage();
//get hold of the area that contains the block we want to include
$globalScrapbookArea = Area::getOrCreate( $myc, 'mailchimptest' );
//now load the block by the name you gave it in the scrapbook
$block = Block::getByName('mc');
$block->setBlockAreaObject($globalScrapbookArea);
if( $block && $block->bID) $block->display();


2. Having done this - I need the code that creates the action link in the view.php to understand that it must post the ajax call to the correct instance of the page:
//create the action in the normal way
$action = str_replace("&","&",$this->action('mailchimp_subscribe'));
$action = str_replace(" ","%20",$action);
//now get see if the owning collection of this block is the same as the scrapbook
$scrapbookHelper=Loader::helper('concrete/scrapbook');
$pg = $scrapbookHelper->getGlobalScrapbookPage();
$co = $controller->getCollectionObject();
if ($pg->cID == $co->cID) {
  //it is the same - therefore we need to change the collection that this ajax posts to to be the scrapbook one and not the page its on.
  $c = Page::getCurrentPage();
  $action = str_replace('cID='.$c->cID, 'cID='.$co->cID, $action);  
}


Well - its working for me so far - I'll do some more checking because this is part of my mailchimp block I sell so needs to work :)

Richard
savan replied on at Permalink Reply
Hi Richard,

Your reply exactly helped me how i wanted it. I lately again came to the same issue and it helped me thank you very much