Call Page Area from a block
Permalink
I need to call a page area content from a block. In that area i've other blocks.
I tried to call page area from a page type and it works, but if i call it from the block template and place the block to an other page it does not work. Could you please give an idea if it is possible, how?
Thanks.
the below code is working and i can display the content of the "the_area" content which is in "the_page" page from other page template...
I tried to call page area from a page type and it works, but if i call it from the block template and place the block to an other page it does not work. Could you please give an idea if it is possible, how?
Thanks.
the below code is working and i can display the content of the "the_area" content which is in "the_page" page from other page template...
$sourcePage = Page::getByPath("/the_page"); // print_r($sourcePage); $sourceArea = new Area("the_area"); $sourceBlocks = $sourceArea->getAreaBlocksArray($sourcePage); //print_r($sourceBlocks); exit; $outputArea = new Area("new_area"); //$outputArea->setCustomTemplate("block_handle", "templates/my_template.php"); $outputArea->disableControls(); $outputArea->display($c, $sourceBlocks);
Does it work if you add this to the top?
Nope,
actually i already got that on top of the page, i just did not include it while copy/pasting.
The code works when i call it from a page template, but i want to call it from a block, autonav, to include some content within mega menu...
Thanks though.
actually i already got that on top of the page, i just did not include it while copy/pasting.
The code works when i call it from a page template, but i want to call it from a block, autonav, to include some content within mega menu...
Thanks though.
Looking at this more closely, I don't think you can create a new area on a page with a block, if you are just trying to output the content of the blocks from another page, I think you could just do this
$sourcePage = Page::getByPath("/the_page"); $sourceArea = new Area("the_area"); $sourceBlocks = $sourceArea->getAreaBlocksArray($sourcePage); foreach($sourceBlocks as $block){ $block->display(); }