Share data base table content from the block
Permalink
Hi all,
sorry if it doubled somewhere, please link me then,
but I can't find the answer on my question.
For example I have the block on one page with fields
"name", "position", "about".
On the other page I need the content from the same table, but just with fields "name", "position". That is like preview.
So I want to edit content for these fields from one place, but use them in several. How to do that?
Thanks in advance for any help.
sorry if it doubled somewhere, please link me then,
but I can't find the answer on my question.
For example I have the block on one page with fields
"name", "position", "about".
On the other page I need the content from the same table, but just with fields "name", "position". That is like preview.
So I want to edit content for these fields from one place, but use them in several. How to do that?
Thanks in advance for any help.
You would need a custom block that pulls all the information out you want and then, create custom templates to display only the information you require.
It's a bit tricky to do. Are you a php coder at all? If so, you can create the new block with a field for "target CID" (that is, the collection ID [i.e. "page id"] of the page that has the original blocks on it). Put a page selector on its add/edit form so the user can choose the page from which to pull the bio information from. Then in the view() method of the new block, you can do something like this:
$page = Page::getByID($this->targetCID); //<--name of new block's CID/"page id" field $blocks = $page->getBlocks('Main'); //<--name of the area in the target page that the other blocks exist in (note that this doesn't work if the area has "Layouts") $items = array(); foreach ($blocks as $block) { if ($block->btHandle == 'your_other_block_handle') { //<--handle of the block type you want to pull data from $name = $block->getInstance()->name; //assumes "name" is the name of that block's database field for that info $position = $block->getInstance()->position; //assumes "position" is the name of that block's database field for that info $items[] = array( 'name' => $name, 'position' => $position, ); } } //NOW the $items variable contains an array of info. Pass it to the view, loop through it and print out the data you need in the proper format.
This biographies add-on does something similar. On one page displaying biographies, but using info from all the the biographies blocks in a single contact list block.
http://www.concrete5.org/marketplace/addons/eantics-biographies/...
http://www.concrete5.org/marketplace/addons/eantics-biographies/...
Thanks guys to all of you for ideas,
it fixed now,
so I have block for the page with full info and template where I pull out the fields from the table of this block as TheRealSean suggested.
But I needed the last version data in that block database.. so in the controller to that page:
and then in the page I access that fields like that
jordanlev, thanks for getInstance(), I'm using it in another place as well!
it fixed now,
so I have block for the page with full info and template where I pull out the fields from the table of this block as TheRealSean suggested.
But I needed the last version data in that block database.. so in the controller to that page:
$page = Page::getByPath('/contact/management_team'); //page with full info $v_id = $page->getVersionObject()->getVersionId(); $db = Loader::db(); $sql = " select * from btteamblock as t // database table with full info join collectionversionblocks as cv using(bID) where cv.cvID = $v_id order by cbDisplayOrder asc "; $contacts = $db->Execute($sql)->GetRows(); $this->set('cont',$contacts);
and then in the page I access that fields like that
<?php print_r($contact['full_name']); ?>
jordanlev, thanks for getInstance(), I'm using it in another place as well!