Extract content from more than one area?

Permalink Browser Info Environment
Hi there

Would it be possible to make this template extract content from more than one area? I'd like to extract text from the Main area, but an image from an area called Image (so the image can be displayed alongside the text in the teaser).

Cheers

Laurence

Type: Discussion
Status: New
melat0nin
View Replies:
jordanlev replied on at Permalink Reply
jordanlev
This is pretty easy to do.

Edit this file:
YOURSITE/packages/page_list_teasers/helpers/page_list_teasers.php

...and change these two lines (should be around lines #5 and 6):
public function output_page_blocks($collectionObject, $maxBlocks = null, $truncateChars = 0, $blockWrapperStart = '', $blockWrapperEnd = '', $ignoreBlockTypes = array('page_list')) {
   $areaHandle = defined('PAGE_LIST_TEASERS_AREA') ? PAGE_LIST_TEASERS_AREA : 'Main';

...to this:
public function output_page_blocks($collectionObject, $maxBlocks = null, $truncateChars = 0, $areaHandle = null, $blockWrapperStart = '', $blockWrapperEnd = '', $ignoreBlockTypes = array('page_list')) {
    $areaHandle = empty($areaHandle) ? (defined('PAGE_LIST_TEASERS_AREA') ? PAGE_LIST_TEASERS_AREA : 'Main') : $areaHandle;


Then edit this file:
YOURSITE/packages/page_list_teasers/blocks/page_list/teasers.php

...and find this line (should be around line #26):
<?php $plth->output_page_blocks($cobj, $excerptBlocks, $truncateChars); ?>

...and underneath it, add this line:
<?php $plth->output_page_blocks($cobj, $excerptBlocks, $truncateChars, 'Image'); ?>
Responsive replied on at Permalink Reply
Responsive
Hi Jordan
can you please let me know how we would do this on the latest version as the code has changed since the last post.
thanks
jordanlev replied on at Permalink Reply
jordanlev
Sure. This is actually easier now in the new version. No need to change the helper file, just modify the template:

1) Copy this file:
SITEROOT/packages/page_list_teasers/blocks/page_list/templates/teasers.php

...to here:
SITEROOT/blocks/page_list/templates/teasers.php


2) Edit the new copy of the template file (SITEROOT/blocks/page_list/templates/teasers.php), and find this line (should be around line #17):
$teaser = $plth->getPageTeaser($page, 'Main', $teaserBlockCount, $teaserTruncateChars);

...and below it add this new line:
$teaser .= $plth->getPageTeaser($page, 'Image', $teaserBlockCount, $teaserTruncateChars);


-Jordan
Responsive replied on at Permalink Reply 1 Attachment
Responsive
thanks Jordan that was easy . Im not a programmer but also added the following line after this to display an attribute and that worked. Not sure how i would get the words 'Date From' to show before the attribute.

$teaser .= $page->getAttribute('event_date_from');


I did try the following but it seems to repeat the event date shown in the attachment.

<?php  foreach ($pages as $page):
      $title = $th->entities($page->getCollectionName());
      $url = $nh->getLinkToCollection($page);
      $target = ($page->getCollectionPointerExternalLink() != '' && $page->openCollectionPointerExternalLinkInNewWindow()) ? '_blank' : $page->getAttribute('nav_target');
      $target = empty($target) ? '_self' : $target;
      $teaser = $plth->getPageTeaser($page, 'Main', $teaserBlockCount, $teaserTruncateChars);
      $teaser .= $plth->getPageTeaser($page, 'Last_content_box', $teaserBlockCount, $teaserTruncateChars);
      $eventdate .= $page->getAttribute('Event_Date_From');
      ?>
      <h3 class="ccm-page-list-title">
         <a href="<?php  echo $url; ?>" target="<?php  echo $target; ?>"><?php  echo $title; ?></a>
      </h3>
        <h2 class="ccm-page-list-eventdate">
         <?php echo t('Event Date')?> <?php  echo $eventdate; ?>
      </h2>
jordanlev replied on at Permalink Reply
jordanlev
Try changing this:
$eventdate .= $page->getAttribute('Event_Date_From');

...to this:
$eventdate = $page->getAttribute('Event_Date_From');

Note that I changed the ".=" to just "=". In php, an equal sign (=) puts something into a variable (in this case, it's putting the attribute text into the "$eventdate" variable). But a dot-equal-sign (.=) ADDS something to the end of what's already in the variable -- which means every new item in the loop is adding the new event date to the last one. you don't want this -- you want each event date in the loop to be its own thing and overwrite the one that was leftover from last time.

Hope that makes sense.

-Jordan
Responsive replied on at Permalink Reply
Responsive
Many Thanks Jordan , it works now

concrete5 Environment Information

Browser User-Agent String

Hide Post Content

This will replace the post content with the message: "Content has been removed by an Administrator"

Hide Content

Request Refund

You have not specified a license for this support ticket. You must have a valid license assigned to a support ticket to request a refund.