2016-12-04 6 views
0

페이지를 프로그래밍 방식으로 만들고 콘텐츠 블록에 콘텐츠를 삽입하고 있지만 콘텐츠 블록을 만든 후에는 composer를 통해 편집 할 수 없습니다 (core_page_type_composer_control_output이 아니기 때문에 일반 콘텐츠 블록이기 때문에). . 프로그래밍 방식으로 페이지에 블록을 추가하고 Composer에서 멋지게 재생할 수있는 방법이 있습니까? 내가 사용작곡가 컨트롤 출력 블록을 문법적으로 추가하기

관련 코드 :

$page = Page::getByPath('/articles/xxx'); 
$block = BlockType::getByHandle('content'); 
$data = array(
    'content' => 'the content', 
); 
$page->addBlock($block, 'Main', $data); 

답변

0

내가 설정 당신이 작곡가로 페이지를 작성하는 것처럼 pagetype에을 것,이를 달성하기 위해.
(콘텐츠 블록을 작성자와 pagetype의 표준 출력에 추가)

페이지를 만든 후에는 작성자 연결 콘텐츠 블록이 있지만 완전히 비어 있습니다. 그런 다음 '메인'영역에 새 블록을 작성하는 대신 블록을 업데이트합니다.

코드 예제 (을 테스트하지) :

$page = Page::getByPath('/articles/xxx'); 
$blocks = $page->getBlocks('Main'); 
if(!empty($blocks)){ 
    foreach($blocks as $block){ 
    //check if the blocktype is content 
    if($block->getBlockTypeHandle() == 'content'){ 
     //we are pretty sure this is the content block in the main area 
     //because it's the only content block present... updating the block content 
     $data = array(
       'content' => 'the content', 
      ); 
     $block->update($data) 
    } 
    } 
}