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

Use content from About Us page on a section of Homepage


Go to End


10 Posts   2587 Views

Avatar
doubleedesign

Community Member, 19 Posts

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.

Avatar
swaiba

Forum Moderator, 1899 Posts

13 October 2010 at 12:17am

Edited: 13/10/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

Avatar
ttyl

Community Member, 114 Posts

13 October 2010 at 7:56am

Edited: 13/10/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

Avatar
swaiba

Forum Moderator, 1899 Posts

13 October 2010 at 8:56am

nice:)

Avatar
ttyl

Community Member, 114 Posts

13 October 2010 at 9:34am

also allows you to create shell pages with different permissions.

Avatar
doubleedesign

Community Member, 19 Posts

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.

Avatar
Willr

Forum Moderator, 5523 Posts

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 %>

Avatar
doubleedesign

Community Member, 19 Posts

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!

Go to Top