Modify Page List Block

Permalink 1 user found helpful
Hi guys,

I been looking around the site for this but haven't found anything. But I would like to modify the page list block, so it displays the first paragraph of the content area ( in relation to its link). Is this possible?

Thanks in advance
Ritch

View Replies:
roa123 replied on at Permalink Reply
Hey guys any thoughts?
synlag replied on at Permalink Reply
synlag
i submitted already an extended page list block, where you can choose which attributes of the displayed pages should appear.
Coming soon.
okhayat replied on at Permalink Reply
okhayat
I needed something similar and created the attached template.
It will list the page titles and the portion of the 'Content Block' text before the <!-- pagebreak --> mark, which is added from the TinyMCE editor toolbar (Advanced Mode).
To use it, create the directory structure:
{your_site_path}/blocks/page_list/templates
and create a file called content_intro.php there, with the following content:
<?php 
defined('C5_EXECUTE') or die(_("Access Denied."));
if (count($cArray) > 0) { ?>
<div class="ccm-page-list">
   <?php 
   for ($i = 0; $i < count($cArray); $i++ ) {
      $cobj = $cArray[$i]; 
      $title = $cobj->getCollectionName();
      $blocks = $cobj->getBlocks('main');
   ?>
   <h3 class="ccm-page-list-title">
      <a href="<?php echo $nh->getLinkToCollection($cobj)?>"><?php echo $title?></a>
   </h3>
   <div class="ccm-page-list-description">
   <?php

When done, edit the page where you want to use this template, click on the page_list block you have and choose 'Custom Template' and select the 'Content Intro' from the list.
roa123 replied on at Permalink Reply
Thanks guys, i'll give it a go and let you know if i run into any problems
roa123 replied on at Permalink Reply
Thanks okhayat that code worked beautifully and also was able to integrate truncation on it!
hexacreative replied on at Permalink Reply
hexacreative
How about insert the image? the image before <!--- page break ---!> is not shown. Thanks
jordanlev replied on at Permalink Reply
jordanlev
Thanks okhayat -- this is GREAT! I figured out how to fix the issue that hexacreative was having where the images weren't being displayed -- instead of calling $bi->content, use $bi->getContent() which will insert the proper urls to files in the content. Note that this only shows images that are inside a content block -- it will not retrieve images that are in a separate "image" block on the page (only "content" blocks are examined with this code).
Also note that I changed the area name this code looks for from 'main' to 'Main' (capitalized the "M") because that's what it's called in my page type / template. Change this as appropriate for your page type / template.

<?php
defined('C5_EXECUTE') or die(_("Access Denied."));
if (count($cArray) > 0) { ?>
<div class="ccm-page-list">
   <?php
   for ($i = 0; $i < count($cArray); $i++ ) {
      $cobj = $cArray[$i];
      $title = $cobj->getCollectionName();
      $blocks = $cobj->getBlocks('Main');
   ?>
   <h3 class="ccm-page-list-title">
      <a href="<?php echo $nh->getLinkToCollection($cobj)?>"><?php echo $title?></a>
   </h3>
   <div class="ccm-page-list-description">
   <?php
ericchaffey replied on at Permalink Reply
I hate to dig up such an old post, but I am having the hardest time trying to modify this code to work with the Core Commerce. I am trying to pull the product block from the page to show on the page list. Using this code I can pull a content block no problem, but products seem to be a problem for me. I can't seem to figure out what to replace getContent with. Here is what I have so far.
foreach ($blocks as $bl) {
         if ($bl->btHandle == 'product') {
            $bi = $bl->getInstance();
            $product = $bi->getContent(); 
            $in = strpos($product, '<!-- pagebreak -->');
            echo ($in !== FALSE) ? substr($product,0,$in) : $product;
         }
      }


Any help would be greatly appreciated. Thanks!
jordanlev replied on at Permalink Reply
jordanlev
The "getContent()" function is not a standard Concrete5 thing -- it's just a specific thing that's built into the content block. But it doesn't exist on any other blocks (except the HTML block I think?), so you can't use it for non-content blocks (as you discovered).

You could try looking at the view.php and controller.php files for the Product block to see if there's another way to do it, but there's also a catch-all approach that works for any block, which is to display the block but do so inside an "output buffer", which lets you tell PHP "for the next few lines of code, whatever you were going to output to the browser, instead put it into a variable". Then you can operate on the contents of that variable and when you're done you output it it yourself.

Seehttp://www.concrete5.org/community/forums/customizing_c5/get-the-co... for a decent example of this technique.
ericchaffey replied on at Permalink Reply
Thank you much for giving me some pointers and giving me that link. From what I can tell in the link you provided, that is mainly to be used in the main template, when I tried to use it in the page_list block/template, I just created a mess. I don't seem to have the skillset to modify the examples to do what I want.

There doesn't seem to be a cut and dry way in the product block to show that block that I can see (nothing like getContent from the content block).

I am actually messing around with your excellent Page List Teasers addon. I have run into a couple issues, probably due to my own ignorance.

First, I am trying to get it to work with the ajax page tools. I frankensteined the two together to get it working, mostly, but it breaks my toolbar and I am unable to edit or anything. I am sure this is because there are functions fighting with eachother that I haven't edited yet.

My other problem, that I should probably bring up in the addons forum, is that the template seems to only pull blocks that are manually added, not those that are "auto-generated" (lack of a better description) from the page type defaults. I have only really tested this with the product block and I think this type of block is fairly unique to the Core Commerce addon.

Anyway, thank you much for the help this far. I know it is too much to ask for help on all that, but HELP! Kidding, I would just like a kick in the butt to hopefully show me the light. Thanks!
jordanlev replied on at Permalink Reply
jordanlev
It's going to be hard to help if you need to combine this with ajax page tools because that's a paid addon so I don't have access to its code. You might try posting a support request (click "support" in the sidebar link on its marketplace page).

Aside from that though, here's the exact code I'd use to recreate the "getContent" functionality with the Product block (or any other block for that matter):
foreach ($blocks as $bl) {
  if ($bl->btHandle == 'product') {
    ob_start();
    $bl->display();
    $content = ob_get_contents();
    ob_end_clean();
    $in = strpos($content, '<!-- pagebreak -->');
    echo ($in !== FALSE) ? substr($product, 0, $in) : product;
  }
}


That being said, I don't think this is really going to work because you're splitting up the entire html of the block in the middle, which means there will be all sorts of opening html tags that don't get closed (and things like the image or price may never get outputted if they come after the description).
I think a better solution would be to figure out how to extract just the product's description from the block (so if you can get the product ID from the block, or better yet if you can tap into its underlying product object, then you can get just the description field so you can cut it at the pagebreak -- although again you'll want to watch out for chopping up a paragraph in the middle and not closing its P tag).

This is a very complex thing you're trying to do, by the way, so don't feel too bad if you can't get it working :-/
jordanlev replied on at Permalink Reply
jordanlev
Note that with the new Layouts feature of version 5.4, you need to take some additional steps if any of the pages you're listing have layouts in them. Seehttp://www.concrete5.org/community/forums/customizing_c5/how-to-get... for more details.