Jump to:

22977 Posts in 11742 Topics by 2826 members

General Questions

SilverStripe Forums » General Questions » Use content from About Us page on a section of Homepage

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

Page: 1 2
Go to End
Author Topic: 1459 Views
  • doubleedesign
    Avatar
    Community Member
    19 Posts

    Use content from About Us page on a section of Homepage Link to this post

    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.

  • swaiba
    Avatar
    Forum Moderator
    1769 Posts

    Re: Use content from About Us page on a section of Homepage Link to this post

    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

  • ttyl
    Avatar
    Community Member
    114 Posts

    Re: Use content from About Us page on a section of Homepage Link to this post

    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

  • swaiba
    Avatar
    Forum Moderator
    1769 Posts
  • ttyl
    Avatar
    Community Member
    114 Posts

    Re: Use content from About Us page on a section of Homepage Link to this post

    also allows you to create shell pages with different permissions.

  • doubleedesign
    Avatar
    Community Member
    19 Posts

    Re: Use content from About Us page on a section of Homepage Link to this post

    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.

  • Willr
    Avatar
    Forum Moderator
    5462 Posts

    Re: Use content from About Us page on a section of Homepage Link to this post

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

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

  • doubleedesign
    Avatar
    Community Member
    19 Posts

    Re: Use content from About Us page on a section of Homepage Link to this post

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

    1459 Views
Page: 1 2
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.