Accessing blocks in Page list override

Permalink
So I have a page list block on the home page.

I want it to show one page only in the area.

It looks like page lists are intended to get attributes rather than page content.

I have been looping thru the code below trying to get a block called "Statistic Image" but its always empty. Is it not possible to access blocks in page list?

if (count($cArray) > 0) { ?>
   <?php  
   for ($i = 0; $i < count($cArray); $i++ ) {
      $cobj = $cArray[$i]; 
      $title = $cobj->getCollectionName();
                  $blocks = $cobj->getBlocks('Statistic Image');
      var_dump($blocks);
                ?>


DOH! page was empty so that accounts for some of that.....

alanski
 
ConcreteOwl replied on at Permalink Reply
ConcreteOwl
alanski replied on at Permalink Reply
alanski
Thanks. I finally found part of my answer here:
http://www.concrete5.org/community/forums/customizing_c5/theoretica...

Contained in here is some really crucial distinctions concerning C5 and page lists and building sites.

So now if i have the block data i am still wondering which part of the array in $blocks actually provides the data. $blocks is a huge array some of the content of which is serialised ?!?

How do you render/access the array properly to get the block?
foreach ($pages as $page):
$blocks = $page->getBlocks('Statistic Text');
$blocks->????
mhawke replied on at Permalink Best Answer Reply
mhawke
This might help:

http://www.concrete5.org/marketplace/addons/page-list-teasers/...

If you park the "Statistic Text" block in the 'Main' area on the page then Page List Teasers will grab it's content.
alanski replied on at Permalink Reply
alanski
Yes it does help thanks.

In fact it helped me 'cheat'.

Using Jordans installed add on i borrowed it's helper for a leg up :)
So my page list template looks like:

<?php
defined('C5_EXECUTE') or die("Access Denied.");
$teaserBlockCount = ($controller->truncateSummaries ? 1 : null);
$teaserTruncateChars = ($controller->truncateSummaries ? $controller->truncateChars : 0);
$plth = Loader::helper('page_list_teasers', 'page_list_teasers');
$th = Loader::helper('text');
foreach ($pages as $page):
    $statImage = $plth->getPageTeaser($page, 'Statistic Image', $teaserBlockCount, $teaserTruncateChars);
    $statText = $plth->getPageTeaser($page, 'Statistic Text', $teaserBlockCount, $teaserTruncateChars);
 ?>
    <div class="text-box"> 
        <div class="visual">
    <?php echo $statImage; ?>
        </div>
        <div class="frame">


Note: for anyone reading/discovering the blocks 'Statistic Image' are referencing a block on a custom page template.
mhawke replied on at Permalink Reply
mhawke
Cheat? Open Source + MIT + Free Add-on means that cheating is allowed and encouraged. How do you think we all learned to build in concrete5. Now excuse me while I steal your work and extend it in one of my projects!

UPDATE: After working with the code, I realize that my post above may lead people in the wrong direction. For alanski's code to work, you must have editable areas named 'Statistic Image' and 'Statistic Text' built into the Page Type file that is being grabbed by the Page List block. You can edit the code to reflect the names of the editable areas you actually have in your Page Type files. The template will grab the number of blocks from these areas depending on the configuration of the Page List block (using the Page List Teasers settings). This also assumes you have the free "Page List Teasers" add-on installed on your site.

http://www.concrete5.org/marketplace/addons/page-list-teasers/...