Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Data Model Questions /

Showing image/content of hidden child page in parent page.


Reply


2 Posts   2101 Views

Avatar
Happysadhu

Community Member, 33 Posts

25 July 2009 at 6:03am

Hi,
I am modifying the StaffHolder.php, as instructed in the second tutorial, so that it shows the complete images and content of StaffPages WITHOUT displaying any StaffPages in the menu under the Staff section on the the webpage. I've gotten SS to show the full content of each child StaffPage in the main staffholder page, but not the attached staff image for each entry. I suspect it has something to do with how I have stated the dataobject::get function in the StaffHolder_Controller, which is currently:

public function GetStaffPage(){
return DataObject::get("StaffPage");

It pulls the $Content from each staffpage but not its associated $Photo image?

See code below for more details,

Thanks the help,
Sam Miller

StaffHolder.php

<?php
class StaffHolder extends Page {
static $db = array(
);
static $has_one = array(
);

static $allowed_children = array('StaffPage');
}

class StaffHolder_Controller extends Page_Controller {

public function GetStaffPage(){
return DataObject::get("StaffPage");
}
}

?>

--------------
StaffPage.php

<?php
class StaffPage extends Page {
static $db = array(
);
static $has_one = array(
'Photo' => 'Image'
);

function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldToTab("Root.Content.Images", new ImageField('Photo'));
return $fields;
}

static $defaults = array(
'ShowInMenus' => false
);
static $allowed_children = array('none');
}

class StaffPage_Controller extends Page_Controller {

}
?>

----------
StaffHolder.ss
<div id="entry_content" class="entry_wide">
   <div class="typography">
      <h2>$Title</h2>
      $Content
<ul id="StaffList">
<% control GetStaffPage %>
<li>
<div class="staffname"><p>$Title</p></div>
<div class="staffphoto">$Photo.SetWidth(150)</div>
<div class="staffdescription"><p>$Content</p></div>
</li>
<% end_control %>
</ul>
   </div>
</div>

Avatar
Happysadhu

Community Member, 33 Posts

26 July 2009 at 6:53pm

Hi again,
So I sorted it out. I used <% control AllChildren %> to grab data from hidden child pages, instead of setting up and using the function <% control GetStaffPage>, in the StaffHolder.ss template.

<% control AllChildren %>
<li>
<div class="staffname"><p>$Title</p></div>
<div class="staffphoto">$Photo.SetWidth(150)</div>
<div class="staffdescription"><p>$Content</p></div>
</li>
<% end_control %>

Then I had to recreate my StaffPages and reattached the images under the StaffHolder page in the CMS -- for some reason. Now the images are showing up for each StaffPage in the StaffHolder page.

Sam Miller