Select data from another page

Permalink
Hi. I am trying to write custom block and need to link short version, few lines, of text from another existing page.
Any ideas?
Thanks.

 
okhayat replied on at Permalink Reply
okhayat
Here's a part of a template I wrote for use with the Page List (check thishttp://www.concrete5.org/community/forums/customizing_c5/modify_pag... to do something similar.
<?php
$page = Page::getByID($id);
$blocks = $page->getBlocks('main'); 
foreach ($blocks as $bl) {
  if ($bl->btHandle == 'content') {
    $bi = $bl->getInstance();
    $in = strpos($bi->content, '<!-- pagebreak -->');
    echo substr($bi->content,0,$in);
  }
}?>
babalooi replied on at Permalink Reply
I will try it.
Tnx.
dbaggs replied on at Permalink Reply
dbaggs
Could anyone provide any guidance on how to promote an image from a lower level page up.

My scenario is that I would like to promote the image on many event pages up to the parent events page as well as to the home page.

I've successfully used the tips here to pull the text based block content but need a prod in the right direction for an image.

In truth, I'm finding it hard to get info from the API docs and there is only so far that looking at existing examples can get you so any help would be appreciated.

Regards,

Dan.
Remo replied on at Permalink Reply
Remo
look at the code above..

the block type isn't content but "image" in your case and anything else is pretty much the same..

add print_r($bi) to see what properties you get.
dbaggs replied on at Permalink Reply
dbaggs
Thanks for your reply Remo.

However, I've set up my event pages so that content is constrained and controlled. Therefore, I have an 'Image' area that will only ever contain one image block (through defaults and advanced permissions).

Therefore, I make an assumption with my code in the page_list overridden template, meaning I just take the first element of the blocks array and have no need to iterate through filtering upon type - e.g.:

$imageBlocks = $cobj->getBlocks('Image');
if(sizeof($imageBlocks) > 0)
{
$imageURL = $imageBlocks[0]->getInstance()->content;  
}


So I guess my follow up question is: are you referring to changing
$imageURL = $imageBlocks[0]->getInstance()->content;


to

$imageURL = $imageBlocks[0]->getInstance()->image;


in my example and if so where would I have found this information out myself?

That said, I've tried what you have suggested (or how I interpreted the suggestion) with no further joy.

I have to caveat this response in that I haven't really coded in PHP in earnest before so there could well be something I am not grasping so feel free to treat me like a blonde! ;)

Regards and thanks in advance,

Dan
dbaggs replied on at Permalink Reply
dbaggs
Ok, so I checked out the view.php in the image block and saw:

echo($controller->getContentAndGenerate());


So I've modified my template override to have this, which works:
echo $imageBlocks[0]->getController()->getContentAndGenerate();


Any bad practice here or is this ok?

Regards,

Dan
dbaggs replied on at Permalink Reply
dbaggs
For the benefit of others like me...

As I only wanted the URL to be passed, I've now used:

$imageURL = $imageBlocks[0]->getController()->getFileObject()->getRelativePath();


and then echo'd out the $imageURL in the right location. I found the above code in the controller.php for the image block.

Regards,

Dan.
Remo replied on at Permalink Reply
Remo
yes, this is better!

I don't like getContentAndGenerate a lot. This shouldn't be part of the controller.

Using getFileObject is much better and should work fine as long as the image block itself doesn't change. Very unlikely to happen I think, but calling a blockcontroller is probably not part of "the official API"..

But I'd use it as well..
dbaggs replied on at Permalink Reply
dbaggs
Thanks for your feedback.