use in combination with designer content

Permalink Browser Info Environment
Hi there,

I've made a custom block with designer content. Containing 1: thumbnail, 2: big image, 3: some text.
Now i want to use the pagelist teaser to show just the thumbnail (first in row in the block). But i get the whole content of the block in the teaser list.
Can i change it, so it just shows the thumbnail from the block content?

Type: Discussion
Status: New
buurvrouw
View Replies:
jordanlev replied on at Permalink Reply
jordanlev
Unfortunately Page List Teasers won't work for this situation. It will only show entire blocks in an area and can't get any more fine-grained than that.

I think you can do this fairly easily with some code modifications though...

First, edit your custom block's controller.php file, and find this line of code:
public function view() {

... and insert this new code BEFORE that line:
public function teaserThumbnail() {
    return $this->get_image_object($this->field_1_image_fID, 200, 200, true))
}

NOTE that you may need to change "field_1_image_fID" to the proper field name (depends on how you build your block exactly -- easiest way to find out is probably to look in the view.php file and find the field that's being used in the first <img> tag you see in that file).
ALSO note that the numbers "200" are the resize or crop width and height (respectively), and the "true" tells it to crop (change this to false if you want proportional resize instead).

Next edit this file:
packages/page_list_teasers/helpers/page_list_teasers.php

...and find this chunk of code:
} else {
   $blockForDisplay->display();
}

...and directly BEFORE that chunk of code insert this chunk of code:
} else if ($blockType == 'your_designer_content_block_handle') { //<--change this to the block type handle you entered in the Designer Content dashboard when creating the custom block
   $thumb = $blockForContent->teaserThumbnail();
   echo "<img src=\"{$thumb->src}\" width=\"{$thumb->width}\" height=\"{$thumb->height}\" alt="" />";


I *think* that should work. Do take note of the fact that we had to modify the Page List Teaser package code so if that's ever updated in the future you will need to re-apply this patch.

-Jordan
buurvrouw replied on at Permalink Reply
buurvrouw
Hi Jordan, thanks for your quick reply! But it's not working completely yet...

I've changed all the code like your examples, but then both the teaser-list plus the actual page were getting errors.

Now i have this in my custom block controller:
public function getSearchableContent() {
      return $this->field_2_wysiwyg_content;
   }
   //Added for teasers
   public function teaserThumbnail() {
       return $this->set('field_1_image', $this->get_image_object($this->field_1_image_fID, 201, 140, true));
   }
   //End added for teasers
   public function view() {
      $this->set('field_1_image', $this->get_image_object($this->field_1_image_fID, 201, 140, true));
      $this->set('field_3_image', $this->get_image_object($this->field_1_image_fID, 0, 0, false));
      $this->set('field_2_wysiwyg_content', $this->translateFrom($this->field_2_wysiwyg_content));
   }


Note that i changed the inserted code like it looks in public function view() {
This took away the error in the actual page.

The teaser helper looks like this now:
//Added for designercontent block
         } else if ($blockType == 'testblok') { //<--change this to the block type handle you entered in the Designer Content dashboard when creating the custom block
            $thumb = $blockForContent->teaserThumbnail();
            echo "<img src=\"{$thumb->src}\" width=\"{$thumb->width}\" height=\"{$thumb->height}\" alt="" />";
         //End added for designercontent block
         } else {
            $blockForDisplay->display();
         }
         echo $blockWrapperEnd;


But it's giving me this error:
Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ',' or ';' in /var/www/g45287/fotokunstkado.nl/subdomains/concrete/packages/page_list_teasers/helpers/page_list_teasers.php on line 35

Line 35 is this line:
echo "<img src=\"{$thumb->src}\" width=\"{$thumb->width}\" height=\"{$thumb->height}\" alt="" />";


Do you know where i go wrong?
buurvrouw replied on at Permalink Reply
buurvrouw
Yay! I figured it out and even added the alt tag from the custom block!

In controller.php for custom block i added:
//Added for teasers
   public function teaserAlt() {
       return $this->field_1_image_altText;
   }
   public function teaserThumbnail() {
       return $this->get_image_object($this->field_1_image_fID, 201, 140, true);
   }
   //End added for teasers


In page_list_teasers.php i added:
//Added for designercontent block
         } else if ($blockType == 'testblok') { //<--change this to the block type handle you entered in the Designer Content dashboard when creating the custom block
            $thumb = $blockForContent->teaserThumbnail();
            $thumbAlt = $blockForContent->teaserAlt();
            echo "<img src=\"{$thumb->src}\" width=\"{$thumb->width}\" height=\"{$thumb->height}\" alt=\"{$thumbAlt}\" />";
         //End added for designercontent block


Note that there were missing some escapes in your original code for the alt:
alt=""


Thank you SO MUCH for handing me the right direction Jordan!!
jordanlev replied on at Permalink Reply
jordanlev
You're welcome! Sorry about the alt tag error there! Glad you got it figured out, and this will be a great resource for other people in the future who want to do similar things.
webicine replied on at Permalink Reply
webicine
Hi Jordan, I am trying to use this in C5 5.5.1 with Page List Teasers 1.2 and Designer Content 3.0.2 and it isn't working. It just ends up pulling the whole Designer Content block.

There are some differences in the page_list_teasers.php file, such as there isn't a $blockforDisplay line, but I placed my code directly before the ob_start lines thinking that might work the same.

//Added for designercontent block
         } else if ($blockType == 'product') { //<--change this to the block type handle you entered in the Designer Content dashboard when creating the custom block
            $thumb = $blockForContent->teaserThumbnail();
            echo "<img src=\'{$thumb->src}\' width=\'{$thumb->width}\' height=\'{$thumb->height}\' alt='' />";
         //End added for designercontent block
         } else {
            ob_start();
            $b->display();
            $teaser .= ob_get_clean(); //combines ob_get_contents() and ob_end_clean()
         }


Any suggestions? Or is there a better way to do this now? Basically all I want to display out of my designer content block is the thumbnail and title.
jordanlev replied on at Permalink Reply
jordanlev
I changed the code in a recent version of Page List Teasers (it is more efficient now).

Assuming your designer content block has the "teaserThumbnail()" function, you would modify your page list teaser code so instead of this:
$thumb = $blockForContent->teaserThumbnail();

...you have this:
$bi->teaserThumbnail();

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.