Blog item load block instead of Description (5.6.x)

Permalink 4 users found helpful
Hi,

I am creating a custom pagelist template to display text from composer.

Normally you show the description text. But I like to load the full text from a textblock in the newsitem.
<?php  
                  if(!$controller->truncateSummaries){
                     echo $cobj->getCollectionDescription();
                  }else{
                     echo $textHelper->wordSafeShortText($cobj->getCollectionDescription(),$controller->truncateChars);
                  }
               ?>


So I have to use something like this?
$blocks = $page->getBlocks('Main');


So you see the full text article below each other. (I still have a "click to full article" button if I have other blocks/info in the article.

See attachment for full template code.

1 Attachment

 
hutman replied on at Permalink Reply
hutman
Yes you have to do something like this

$blocks = $page->getBlocks('Main');
foreach($blocks as $block){
     $btHandle = $block->getBlockTypeHandle();
     if($btHandle == 'content'){
          $b->display();
     }
}


This will loop through all of the blocks in this area of your page and if it is a content block output the block content.
TorstenKelsch replied on at Permalink Reply
TorstenKelsch
Corrected ($block instead of $b):

<?php
   $blocks = $page->getBlocks('Main');
   foreach($blocks as $block) {
      $btHandle = $block->getBlockTypeHandle();
      if ($btHandle == 'content') {
         $block->display();
      }
   }
?>


It works in 5.7.x also.
Dutchwave replied on at Permalink Reply
Dutchwave
Great, but how to truncate this text?
TorstenKelsch replied on at Permalink Reply 1 Attachment
TorstenKelsch
I can’t remember this at all and it seems I’ve deleted my code, but I found another code which could be of use, but it is for the page list, not for the single blog entry. In my opinion, truncating makes no sense in single blog entries.

<?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');
   $rssUrl = $plth->getRssUrl($b);
   $th = Loader::helper('text');
   //Note that $nh (navigation helper) is already loaded for us by the controller (for legacy reasons)
?>
<div class="ccm-page-list">
   <?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);


When you are in edit mode, you can click the page list block so that a context menu appears. If you choose Edit, you should be able to type in a number. The text should be truncated if the number of charactes exceeds..
Dutchwave replied on at Permalink Reply
Dutchwave
I used that on C5.6 as well, it needs the Page List Teasers block.
This does not work with C5.7 unfortunately.
Dutchwave replied on at Permalink Reply
Dutchwave
Found a solution in a different thread that works in Verison 8 aswell.

https://www.concrete5.org/community/forums/5-7-discussion/composer-f...

I changed it a bit for my needs:

// get description composer form block content   
        $pBlocks = $page->GetBlocks();
              foreach ($pBlocks as $pBlock){
                    if ($pBlock->btHandle == 'content') {
                        $blockContent = $pBlock->getInstance();
                        $description = $blockContent->getContent();
                        // truncate it to the first paragraph, so we don't pickup unordered feature lists for listings view - td
                        $description = substr($description,0, 260);   
                    }
              }
echo preg_replace('/[^A-Za-z0-9 !@#$%^&*().]/u','', strip_tags($description));
ViktorNova replied on at Permalink Reply
ViktorNova
Thanks for posting this! It's mostly working great for me (in v8.1), but there's a problem:
If a page in the list has multiple content blocks, it doesn't seem to know to display the "main" content block (i.e. the one that shows up in Composer)

Any ideas on how to force this to use the content block that is linked to Composer?

(FYI I tested this out on the "blog" pages on the default C5 demo site, and the only text that shows up is 'Back' =) )