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
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 |
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
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
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:
...to here:
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):
...and below it add this new line:
-Jordan
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
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.
I did try the following but it seems to repeat the event date shown in the attachment.
$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>
Viewing 15 lines of 19 lines. View entire code block.
Try changing this:
...to this:
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
$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
Many Thanks Jordan , it works now
Edit this file:
...and change these two lines (should be around lines #5 and 6):
...to this:
Then edit this file:
...and find this line (should be around line #26):
...and underneath it, add this line: