Embed page list block

Permalink
Hi There,

Is there any documentation for embedding a page list block? I've found this code in the forums:
<?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 = '';
?>


But I'm not sure what all the parameters mean and:
- How to find out a cParentID
- How you would use a custom template

Does anyone have a commented out version or know what the parameters are?

Any help would be much appreciated.

Cheers

Ben

View Replies: View Best Answer
TheRealSean replied on at Permalink Best Answer Reply
TheRealSean
to display it you would need to use render,
$pagelist1->render(templates/custom_template);

As for the meaning of each bit
BlockType::getByHandle('page_list'); grabs the page list block and sets it as the object $pagelist1 in this instance

controller->num amount to display on a single page
controller->cThis, display pages under the current page(I think)
controller->cParentID, If another page enter its ID(cid)
controller->orderBy = 'display_asc';, what it says on the tin
controller->ctID, only show pages of a particular type(collection Type ID)
controller->rss, provide a RSS feed of the pages


there are a couple more bits you can use,
controller->displayFeaturedOnly, displays only pages with an attribute of is_featured uses a boolean value
controller->truncateSummaries, if a description is used decides whether to shorten it uses a boolean value
controller->truncateChars, amount of characters to shorten the description by.
controller->paginate, if more pages then the controller->num decide if you would like the results paginated
cmscss replied on at Permalink Best Answer Reply
OK, so have added this to render a custom template which works:
$pagelist1->render('templates/bs_v_list_5_col'); // Specify a custom template


But after fiddling, I'm still not sure how to get all the parameters working - cParentID seems to render pages at the same level rather than below and adding the page number to the other parameters (cThis, ctID) doesn't seem to do anything.

BTW, sometimes the control panel will render ?cID=136 in the URL but it doesn't always do this - is there a way to reliably view the cID for pages?
cmscss replied on at Permalink Reply
Sorry, my reply was added before seeing yours - will review now - and thanks!
cmscss replied on at Permalink Reply
Awesome mate - thanks heaps.

For my own ref, here's the complete, commented code:
<?php
   $pagelist1 = BlockType::getByHandle('page_list'); // grabs the page list block and sets it as the object $pagelist1 in this instance
   $pagelist1->controller->cThis = ''; // display pages under the current page (I think) - 0 = no, 1 = yes
   $pagelist1->controller->cParentID = '136'; // if another page enter its ID (cid) - 0 must be entered above for cThis
   $pagelist1->controller->ctID =''; // only show pages of a particular type(collection Type ID)
   $pagelist1->controller->num = ''; // amount to display on a single page
   $pagelist1->controller->orderBy = 'display_asc'; // display_asc = Display order ascending, display_desc = Display order descending, chrono_asc = Publish date, alpha_asc = By name ascending, alpha_desc = By name descending
   $pagelist1->controller->rss = ''; // provide a RSS feed of the pages - 0 = no, 1 = yes
   $pagelist1->controller->displayFeaturedOnly = ''; // displays only pages with an attribute of is_featured uses a boolean value - 0 = no, 1 = yes
   $pagelist1->controller->displayAliases = ''; // 0 = no, 1 = yes
   $pagelist1->controller->truncateSummaries = '1'; // if a description is used decides whether to shorten it uses a boolean value - 0 = no, 1 = yes
   $pagelist1->controller->truncateChars = '128'; // amount of characters to shorten the description by.
   $pagelist1->controller->paginate = ''; // if more pages then the controller->num decide if you would like the results paginated - 0 = no, 1 = yes
   $pagelist1->render('templates/bs_v_list_5_col'); // Specify a custom template
?>


So one last thing, how do you find the page ID for pages?
melat0nin replied on at Permalink Reply
melat0nin
How do I filter by another attribute value when hardcoding the block in this way?

It's easy enough when dealing with a Page List object (as opposed to Block) using filter(), but that gives an error when doing it this way.
jordanlev replied on at Permalink Reply
jordanlev
You can't filter by other attributes -- the page list block does not provide that functionality at all. The hard-coding can only do what you could do if you added the block normally, so the only filtering option is the "is_featured" attribute.

That being said, if you are going through the trouble of hardcoding something, you should probably just use the PageList object yourself and then you can do any kind of filtering you want. (The page list block is just a GUI wrapper around the PageList object anyway). The only advantage to using the block instead of the underlying object is that the block gives you the RSS feed. But if you don't need that, then don't use the block.