Embed page list block in template

Permalink 3 users found helpful
I use the following to hard code an auto-nav into a template
$headernav = BlockType::getByHandle('autonav');
         $headernav->controller->displayPages = 'top';
         $headernav->controller->orderBy = 'display_asc';                    
         $headernav->controller->displaySubPages = 'none';                    
         $headernav->render('view');
I'm looking to do the same thing with a page list block displaying only pages under the page I select - anyone know the proper code to do that? Thanks.

hursey013
 
jgarcia replied on at Permalink Best Answer Reply
jgarcia
I believe you have to pass the BlockType object to to an BlockView class. Here's some working code I have that pulls a block from the scrabook directly into a template:

<?php
$b = Block::getByName('MyBlockName');
$bv = new BlockView();
echo  $bv->render($b, 'view');
?>


Of course $b is a Block object, rather than a BlockType object (which you are using) so I'm not really too sure if that makes a difference.
Remo replied on at Permalink Reply
Remo
why? What's wrong with his approach..

He just need to look into controller.php / db.xml to find the proper properties and it should work imo
hursey013 replied on at Permalink Reply
hursey013
Remo - That's basically what I'm starting to do, I was just curious if anyone had already done it for a page list. I just have the basics now
<?php
              $pagelist1 = BlockType::getByHandle('page_list');
            $pagelist1->controller->num = '';
            $pagelist1->controller->cThis = '';
            $pagelist1->controller->cParentID = '';
            $pagelist1->controller->orderBy = 'display_asc'; 
            $pagelist1->controller->ctID ='';
            $pagelist1->controller->rss = '';
            ?>
Is it necessary to have every property the block offers defined in order for it to work? IN other words, do i need to also include truncate summaries, paginate, etc. What I have now isn't working yet.
Remo replied on at Permalink Reply
Remo
there's no answer to that question which is true for all the blocks. I'd have to look into the code..

Some properties are optional, some aren't.

Try to use FireBug, add a page list block with all the properties you want but before you hit "save", inspect all the form elements, the form element name is the var name and the value is the value...
jgarcia replied on at Permalink Reply
jgarcia
Well nothing, I just thought it might be a little easier than having to dig through the code to find the specific values that need to be set. It could potentially get tricky if setting page ID's and things like that. I just thought it might be easier to actually create the block using the normal interface and then pull it into the template from the scrapbook.

Either way works...one might be better than the other just depending on how it is to be used.
sceva replied on at Permalink Reply
sceva
I was looking for a way to easily add blocks to the template.php files. I took jgarcia's advice and made scrapbook items, and then used his code to put the blocks into the template pages, and it is working good so far. Thanks!
hursey013 replied on at Permalink Reply
hursey013
Yeah I agree... with the exception of the auto-nav block, its much easier running things through the scrapbook rather than trying to figure out all the specifics tied to each individual block.
chuacha replied on at Permalink Reply
chuacha
I have tried both approaches, it works great except RSS.
In the case with scrapbook the feed from the pages don't show up on rss page.

Maybe somebody knows why it can be?
jordanlev replied on at Permalink Reply
jordanlev
I'm not sure if this will work, but try changing line #193 of YOURSITE/concrete/blocks/page_list/tools/rss.php from this:
$c = $b->getBlockCollectionObject();

...to this:
$c = Page::getCurrentPage();
chuacha replied on at Permalink Reply
chuacha
hey, jordanlev,
thank you for your response,
but in that file through the path that you've indicated I have just 57 lines and don't have that method getBlockCollectionObject()
I have concrete5.4.1.1 version.. maybe it is some differences due to version?
chuacha replied on at Permalink Reply
chuacha
I have found it!:)
in the controller for the page list block
changed it, but have an error

"Permission Denied
This page list doesn't use the custom blog template, or you don't have permission to access this RSS feed"

I have custom blog template for it.. but controller the same, what can I do to fix it?
jordanlev replied on at Permalink Reply
jordanlev
Yeah, sorry about that -- I did mean the controller file. But it looks like that isn't working, so unfortunately I don't know how to solve your original problem :(
chuacha replied on at Permalink Reply
chuacha
thanks for trying to help anyways!
So I think I'll leave it not embedded for now