List the names of blocks of each page

Permalink
Hello, i just started on concrete5.7 but i have troubles to find some information. I need the documentation of c5.7 and i’m not sure i’m using the better option to do it.

I’m trying to create a block « autonav » where he doesn’t only list the web site but he also list all the block of the added pages.

I would like that this block « atonav custom » can show the names of the page and also the name of each block added on each areas of every pages.

For this, i have on every page two areas : $a = new Area('Main'); $a = new Area('left');

On the view of the block autonav, i created a template of this block where i added on my package

I tried to use the following code for showing the name of those blocks but i can’t do it.

in clear, i would like to get this kind of result :

- Page Home 
- - Block Welcome 
- - Block News 
- Page Informations 
- - Block Blog 
- - Block Newsletter 
- Page Contact 
- - Block Contact form
- - Block Google Maps


If anyone have any idea where i can find this information or what should i do it, please reply to me. Thanks for reading and i hope someone can find what i’m looking for.

 
razorcommerce replied on at Permalink Reply
razorcommerce
Use method getAreaBlocksArray() in the Concrete\Core\Area\Area namespace documentation is at http://concrete5.org/api/source-class-Concrete.Core.Area.Area.html#...

You need to pass $c, a Collection Object in this case the Page.

Example of getting all blocks from area "Main" on homepage (ID = 1).

use Page;
use Area;
$page = Page::getByID(1);
$area = Area::get( $page, 'Main' );
$blocks = $area->getAreaBlocks( $page );


Note there also method getAreaBlocks() but it is protected. Also there are other ways to load areas, there may be a method to load Area from Page like $page->getAreas() but I'm not sure about that.
JohntheFish replied on at Permalink Reply
JohntheFish
Its only practical to get blocks immediately on a page. Once you start to consider blocks in stacks, then custom blocks that pull in stacks, there are so many special cases that you will never find them all.

Generally, if what you are doing with named blocks is critical to your design, it suggests you should re-think how your design is structured.

What immediately springs to mind is you could use another layer of page lists with what you are thinking of as blocks being pages at the next level down. You can always hide pages from navigation and use them as general purpose editable objects.