Hardcode filtered page list with pagination
Permalink 2 users found helpful
Hi all
I've been working with the page list object to manually filter out pages and display their data, and that works great. The only trouble is when it comes to pagination, in which case using a page list *block* (rather than object) seems to be much more straightforward.
Unfortunately it doesn't seem easy (or possible?) to filter a page list block by attribute in the same way it is for a page list object.
Has anyone managed to achieve this? Pointers very welcome -- I know there's a pagination helper but I'm not clear on how to integrate that into other code.
I've been working with the page list object to manually filter out pages and display their data, and that works great. The only trouble is when it comes to pagination, in which case using a page list *block* (rather than object) seems to be much more straightforward.
Unfortunately it doesn't seem easy (or possible?) to filter a page list block by attribute in the same way it is for a page list object.
Has anyone managed to achieve this? Pointers very welcome -- I know there's a pagination helper but I'm not clear on how to integrate that into other code.
Hi,
yeah, but currently at work and I don't have the code for this here.
Take a look at the page list block controller and the view.
If you add a page list block programatically to an area using your filtered page list object, it should work out of the box, when you set paginator to true.
yeah, but currently at work and I don't have the code for this here.
Take a look at the page list block controller and the view.
If you add a page list block programatically to an area using your filtered page list object, it should work out of the box, when you set paginator to true.
Thanks for the reply, synlag. I'll have a look at the page list code to see if I can figure it out (although if you could post your code when you get a chance, that would be really helpful :))
E.g. in your specific page type controller you could add:
and display the specific page data or add it the pagelist to an area.
Loader::model('calendar_event', 'calendar'); Loader::model('page_list'); class HomePageTypeController extends Controller { ... public function on_start(){ $plo = new PageList(); $plo->filterByCollectionTypeHandle('calendar_event'); $plo->filterByAttribute('calendar_event_is_featured', 1); $plo->sortByPublicDateDescending(); $pl = $plo->getPage(); $this->set('pl', $pl); } ... }
and display the specific page data or add it the pagelist to an area.
How do I add it to an area? I'm fine with using the Page List object to get page data, but it's the pagination+object problem that I can't work out. As far as I can tell your code is just passing a pagelist object to the view, but not handling the pagination.
This is what I added to the home page type controller for a various project:
and set it up in the same controller like this
what should work similar to the page list block, I'll try to figure out with an existent page list object.
public function init_gallery( $c, $area, $bname, $template, $files, $args = false ){ $bt = BlockType::getByHandle('gallery'); $data = array(); $data['playback'] = 'ORDER'; $data['thumbnailWidth'] = 3000; $data['thumbnailHeight'] = 415; $data['thumbnailPerRow'] = 1; $data['maxThumbs'] = 0; $data['thumbnailAttributeKeyID'] = 0; $data['shownAttributes'] = ''; $data['type'] = 'CUSTOM'; $data['imgFIDs'][] = 0; if(is_array($files)) { for ($i=0; $i < count($files); ++$i) { $data['imgFIDs'][$i] = $files[$i]->getFileID();
Viewing 15 lines of 23 lines. View entire code block.
and set it up in the same controller like this
public function on_start(){ $c = $this->getCollectionObject(); $p = RealEstateMultipleFilesAttributeTypeController::getFiles($photos); if(is_array($p)) $this->init_gallery($c, 'Main', 'Homebilder', 'home_slideshow', $p); }
what should work similar to the page list block, I'll try to figure out with an existent page list object.
Ah I see, so the idea is to use a page list object to build an array of filtered pages, then pass this into a block?
I'll attempt it and see how I get on :)
I'll attempt it and see how I get on :)
Wow, I have it (sort of) working, except that it's creating a new Area every time the page is loaded!
Here's my template code (simple creation of an area):
and the controller:
Not sure why that should be because the area name is definitely correct ('Main'). The attribute filter doesn't seem to be working either ("$plo->filter(false, "(ak_project_relevance LIKE '%\nScotland\n%')")"), not sure why that should be. Apart from that pagination seems to be working!
Here's my template code (simple creation of an area):
$a = new Area('Main'); $a->display($c);
and the controller:
public function init_pagelist($c, $area, $bname, $template, $pages, $args = false) { $bt = BlockType::getByHandle('page_list'); $data = array(); $data['num'] = 1; $data['cParentID'] = 205; $data['orderBy'] = 'chrono_desc'; $data['ctID'] = 16; $data['paginate'] = 1; $data['rss'] = 0; $data['displayAliases'] = 0; /*if (is_array($pages)) { for ($i=0; $i<count($pages); $i++) { $data['cID'][$i] = $pages[$i]->getCollectionID(); } }*/
Viewing 15 lines of 29 lines. View entire code block.
Not sure why that should be because the area name is definitely correct ('Main'). The attribute filter doesn't seem to be working either ("$plo->filter(false, "(ak_project_relevance LIKE '%\nScotland\n%')")"), not sure why that should be. Apart from that pagination seems to be working!
Does it create another area or another page list block?
I think it creates the block again, adding it to that particular area every time you're viewing it. Grab the block in your on_view function and delete it, before you add it again.
I think it creates the block again, adding it to that particular area every time you're viewing it. Grab the block in your on_view function and delete it, before you add it again.
Sorry yes you're right, it's creating the block again each time. Will try your suggestion!
sth like this:
Probably disable editing for the area you're adding the block programmatically.
public function on_start() { $c = $this->getCollectionObject(); $blocks = $c->getBlocks('Main'); foreach($blocks as $b) { $b->deleteBlock(); } ..... }
Probably disable editing for the area you're adding the block programmatically.
Hmm that works, but it seems to break pagination, because the block is deleted with each pageview so presumably it always resets itself to the first page. Here's my on_start():
public function on_start() { $c = $this->getCollectionObject(); $blocks = $c->getBlocks('Newsarea'); foreach($blocks as $b) { $b->deleteBlock(); } $plo = new PageList(); $plo->filterByCollectionTypeHandle('news'); //$plo->filter(false, "(ak_project_relevance LIKE '%\nScotland\n%')"); //$plo->sortByPublicDateDescending(); $pl = $plo->get(); $this->init_pagelist($c, 'Newsarea', 'Newslist', 'view', $pl); }
Ok,
might be better to not delete the block then if the request is with pagination, or if the block already exists, but then not reinitialze it.
might be better to not delete the block then if the request is with pagination, or if the block already exists, but then not reinitialze it.
Hmm can you explain what you mean by not reinitializing the block?
The need for pagination is really the only reason I'm doing it like this -- otherwise I'd just iterate through an ordinary page list object and output each page's data. Seems sensible to use the inbuilt pagination helper though.
The need for pagination is really the only reason I'm doing it like this -- otherwise I'd just iterate through an ordinary page list object and output each page's data. Seems sensible to use the inbuilt pagination helper though.
I got the answer over here:http://www.concrete5.org/community/forums/customizing_c5/pagination...
:-)
:-)
Anyone have any ideas?