Jump to:

3450 Posts in 1063 Topics by 738 members

Data Model Questions

SilverStripe Forums » Data Model Questions » Showing image/content of hidden child page in parent page.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 2053 Views
  • Happysadhu
    Avatar
    Community Member
    33 Posts

    Showing image/content of hidden child page in parent page. Link to this post

    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>

  • Happysadhu
    Avatar
    Community Member
    33 Posts

    Re: Showing image/content of hidden child page in parent page. Link to this post

    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

    2053 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.