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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Place data from one set of pages on another


Go to End


3 Posts   954 Views

Avatar
DeklinKelly

Community Member, 197 Posts

13 May 2009 at 8:31am

I want a template named PreviewIndex.ss to place ALL the values from ALL 'PortfolioIdentity' pages on it.

What should I put in PreviewIndex.ss and PreviewIndex.php to get all the data from PortfolioIdentity?

<?php

/// PortfolioIdentity.php
class PortfolioIdentity extends Page {

   static $db = array(

      'ItemTitle' => 'Text',
      'ItemSummary' => 'Text'
   );

   static $has_one = array(

      'Icon' => 'Image'

   );

   function getCMSFields() {

      $fields = parent::getCMSFields();

      $fields->addFieldToTab("Root.Content.PortfolioIndex", new ImageField('Icon','Item Icon'));

      $fields->addFieldToTab("Root.Content.PortfolioIndex", new TextField('ItemTitle','Item Title'));

      $fields->addFieldToTab("Root.Content.PortfolioIndex", new TextField('ItemSummary','Item Summary'));

      return $fields;

   }

}

class PortfolioIdentity_Controller extends Page_Controller {

}

?>

Avatar
Carbon Crayon

Community Member, 598 Posts

13 May 2009 at 10:23pm

Edited: 13/05/2009 10:24pm

hi hknight

in your PreviewIndex_Controller class you want a function like this:

public function GetPortfolios(){

return DataObject::get("PortfolioIdentity");

}

Then in your PreviewIndex.ss you can do something like this:

<% control GetPortfolios %>
<h2>$ItemTitle</h2>
<p>$ItemSummary</p>
$Icon
<% end_control %>

Hope that helps :)

Avatar
DeklinKelly

Community Member, 197 Posts

14 May 2009 at 12:10am

Thanks aram, this is exactly what I needed, and it is so easy to implement!