21280 Posts in 5729 Topics by 2600 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, Howard, Sean, Ryan M., biapar, Willr, Ingo, swaiba, simon_w
| Go to End | Next > | |
| Author | Topic: | 1246 Views |
-
Use content from About Us page on a section of Homepage

12 October 2010 at 11:53pm
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.
-
Re: Use content from About Us page on a section of Homepage

13 October 2010 at 12:17am Last edited: 13 October 2010 12:37am
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
-
Re: Use content from About Us page on a section of Homepage

13 October 2010 at 7:56am Last edited: 13 October 2010 10:36am
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 -
Re: Use content from About Us page on a section of Homepage

13 October 2010 at 9:34am
also allows you to create shell pages with different permissions.
-
Re: Use content from About Us page on a section of Homepage

13 October 2010 at 1:19pm
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.
-
Re: Use content from About Us page on a section of Homepage

13 October 2010 at 4:25pm
Or skip over the PHP and in your homepage template just do
<% control Page(about-us) %>
$Content
<% end_control %> -
Re: Use content from About Us page on a section of Homepage

13 October 2010 at 4:45pm
Thank you so much Willr, that's absolutely perfect and will come in handy a few more times on this site too! Thank you!
| 1246 Views | ||
| Go to Top | Next > |




