Hardcode Pagelist cParentID - beneath this page?
Permalink 2 users found helpful
Hi,
When you add the pagelist block, you have the option to select 'Location - beneath this page'. However when you hardcode the pagelist, i do not see an option to replicate this generic location, you can only specify one parentID location.
My hardcoded block needs to be generic so it will always display the subpages of the level it is at.
Can anyone help
When you add the pagelist block, you have the option to select 'Location - beneath this page'. However when you hardcode the pagelist, i do not see an option to replicate this generic location, you can only specify one parentID location.
My hardcoded block needs to be generic so it will always display the subpages of the level it is at.
Can anyone help
Sorry to bring this up but it was the only post I could find on this.
I can't get cThis to work - the embedded block just displays all pages if I use:
If I inspect the radio buttons, I don't see cThis anywhere - I've tried using the options I do see but can't seem to make them work sorry.
Anyone done this?
Cheers
Ben
I can't get cThis to work - the embedded block just displays all pages if I use:
<?php $pagelistBT = BlockType::getByHandle('page_list'); // grabs the page list block and sets it as the object $pagelistBT in this instance $pagelistBT->controller->cThis = 'true'; // display pages under the current page 'true' 'false' $pagelistBT->controller->num = '0'; // amount to display on a single page $pagelistBT->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 $pagelistBT->controller->rss = '0'; // provide a RSS feed of the pages - 0 = no, 1 = yes $pagelistBT->controller->displayFeaturedOnly = '0'; // displays only pages with an attribute of is_featured uses a boolean value - 0 = no, 1 = yes $pagelistBT->controller->displayAliases = '1'; // 0 = no, 1 = yes $pagelistBT->controller->truncateSummaries = '1'; // if a description is used decides whether to shorten it uses a boolean value - 0 = no, 1 = yes $pagelistBT->controller->truncateChars = '128'; // amount of characters to shorten the description by. $pagelistBT->controller->paginate = '0'; // if more pages then the controller->num decide if you would like the results paginated - 0 = no, 1 = yes $pagelistBT->render('templates/1_column_text_image'); // Specify a custom template ?>
If I inspect the radio buttons, I don't see cThis anywhere - I've tried using the options I do see but can't seem to make them work sorry.
Anyone done this?
Cheers
Ben
I just looked through the page_list code... it appears that you need to set "cParentID" to a non-zero value in order for the "cThis" functionality to work. (I don't understand the logic behind this, but that's just the way it is).
So try adding this line under the "cThis" line you already have:
So try adding this line under the "cThis" line you already have:
$pagelistBT->controller->cParentID = 1; //page_list controller ignores 'cThis' unless you set cParentID to a non-zero value
Thanks mate,
Am working on the project this morning so will check it out.
Cheers
Ben
Am working on the project this morning so will check it out.
Cheers
Ben
Just wondering, is there a way to set the hard coded page list block to show pages from the level above?
I'm trying to add a page list block for recent blog posts in the actual blog entry. I have two separate blog sections on the website, so I can't simply choose a page in Defaults or hard code a certain page ID, since it needs to be different for each blog. Any ideas?
I'm trying to add a page list block for recent blog posts in the actual blog entry. I have two separate blog sections on the website, so I can't simply choose a page in Defaults or hard code a certain page ID, since it needs to be different for each blog. Any ideas?
Not sure, but off the top of my head this might work:
That being said, in general it is a bad practice to "hardcode" blocks to your theme templates, because then they can't get cached. A better solution I've found is to put a global area in your template and add the block to that. If you don't want users being able to edit the block, you can do this so that it is only editable from the "Page Default" in the dashboard:
-Jordan
$pagelistBT->controller->cParentID = Page::getCurrentPage()->getCollectionParentID();
That being said, in general it is a bad practice to "hardcode" blocks to your theme templates, because then they can't get cached. A better solution I've found is to put a global area in your template and add the block to that. If you don't want users being able to edit the block, you can do this so that it is only editable from the "Page Default" in the dashboard:
$a = new GlobalArea('Your Area Name'); if ($c->getMasterCollectionID() != $c->getCollectionID()) { $a->disableControls(); //only allow editing in dashboard Page Defaults } $a->display();
-Jordan
Thanks for replying Jordan. I actually put an if statement in the hard coded block and that seems to work for me, although I might try your method and see if that works since it looks neater.
The only thing about using a normal global block is that I wouldn't then be able to get the settings I need, that being showing the parents level pages. I'm not sure if the fact that it doesn't get cached is such a bad thing, since it's just a list of recent blog posts, no images or anything, just text.
The only thing about using a normal global block is that I wouldn't then be able to get the settings I need, that being showing the parents level pages. I'm not sure if the fact that it doesn't get cached is such a bad thing, since it's just a list of recent blog posts, no images or anything, just text.
In general, you can find these out by using Firebug (in Firefox) or Web Inspector (in Chrome or Safari) by editing a page list block and inspecting the form fields in the add/edit dialog -- the name of the form element will be the field name, and for dropdowns look at the option values to see what the valid options are.