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.

General Questions

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

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

Use content from About Us page on a section of Homepage


Go to End
Reply

10 Posts   1591 Views

Avatar
doubleedesign

12 October 2010 at 11:53pm Community Member, 19 Posts

What I am trying to do is somewhat similar to the news section in the tutorial, only without the Holder, sort of.

Basically I have an about-us page, and I want the content from that to also appear on the homepage (which also has other things on it). I'm a beginner with SilverStripe so I'm at a bit of a loss as to how to do this, so any suggestions would be most appreciated.

Avatar
swaiba

13 October 2010 at 12:17am (Last edited: 13 October 2010 12:37am), Forum Moderator, 1796 Posts

in the hompepage controller...

function AboutUsContent()
{
$doAboutUsPage = DataObject::get_one('Page',"URLSegment = '<url segment of aboutus page>'");
if ($doAboutUsPage) return $doAboutUsPage->Content;
else return 'No About Us Page';
}

add this in your homepage template...

$AboutUsContent

Avatar
ttyl

13 October 2010 at 7:56am (Last edited: 13 October 2010 10:36am), Community Member, 114 Posts

if you want to select the page from the CMS you can do something like this...

   static $has_one = array(
      'Page' => 'Page'
   );

   function getCMSFields() {
      $fields = parent::getCMSFields();
      
      $tablefield_page = new HasOneDataObjectManager(
         $this,
         'Page',
         'Page',
         array('Title' => 'Title'),
         'getCMSFields_forPopup'
      );

      $tablefield_page->setPermissions(array());

      $fields->addFieldToTab('Root.Content.Page', $tablefield_page);

      return $fields;
   }// getCMSFields

....

   function getPageContent(){
      return DataObject::get_by_id('Page', $this->PageID);
   }// getPageContent

Avatar
swaiba

13 October 2010 at 8:56am Forum Moderator, 1796 Posts

nice:)

Avatar
ttyl

13 October 2010 at 9:34am Community Member, 114 Posts

also allows you to create shell pages with different permissions.

Avatar
doubleedesign

13 October 2010 at 1:19pm Community Member, 19 Posts

Thanks swaiba, that looks perfect, but I can't quite get it going, it's just returning "No About Us Page."With my limited knowledge of PHP the error is probably right under my nose.

function AboutUsContent() {
   $doAboutUsPage = DataObject::get_one('Page',"URLSegment = '/about-us/'");
   if ($doAboutUsPage) return $doAboutUsPage->$Content;
   else return 'No About Us Page';
   }

Since it's returning the else condition fine, I'm guessing my URLSegment is wrong? I tried searching for how it should be written but haven't found anything specific enough to this issue.

Avatar
Willr

13 October 2010 at 4:25pm Forum Moderator, 5511 Posts

Or skip over the PHP and in your homepage template just do

<% control Page(about-us) %>
$Content
<% end_control %>

Avatar
doubleedesign

13 October 2010 at 4:45pm Community Member, 19 Posts

Thank you so much Willr, that's absolutely perfect and will come in handy a few more times on this site too! Thank you!

Go to Top