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.

Themes /

Discuss SilverStripe Themes.

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

Getting the home page


Go to End


13 Posts   7078 Views

Avatar
yurigoul

Community Member, 203 Posts

30 October 2009 at 1:46pm

Edited: 31/10/2009 12:12am

Don't apologize, you came back for a reply didn't you :-)

I was going to say that hiding the page name field would hide it from other pages as well - but that would be the case if you do it with css.

But with $fields->removeFieldFromTab("Root.Content.Main","Title"); in your templateforhomePage.php you could do just that.

And after I did a dev/build I indeed noticed that a new homepage was made, so it might even be a good idea to hide the Title-field from just the homepage. You can even give another page the name home, and it will be renamed to /home-2. Now I just have to find the page where all the settings and options for page.php are given, maybe there is a setting that I can also protect that page some more ... All the info we need is here and on the doku websites, sometimes the only problem is how to find it. I am constantly asking myself how that could be improved.

Now I am off to bed! Cheers!

EDIT: you also have to give $fields->removeFieldFromTab("Root.Content.Metadata","URL"); in order to protect against people changing a page name/url

Avatar
bummzack

Community Member, 904 Posts

30 October 2009 at 8:07pm

Hey yuirgoul

I don't like relying on the URLSegment either. For almost all the Sites I created, I used a special HomePage class that can only be created once. To ensure this, you'll have to override the canCreate method of the HomePage, something along the lines of:

public function canCreate($member = null){
	$rights = parent::canCreate($member);
	if($rights == false)
		return false;
		
	$dobj = DataObject::get('HomePage');
	if(!$dobj)
		return true;
		
	return $dobj->Count() == 0;
}

On your Page_Controller you would have something like:

public function getHomePage(){
	return DataObject::get_one('HomePage');
}

...to get the HomePage. I understand that there might be several HomePages when using Translatable. That can be solved by adding a where clause to the get_one statement. Like this:

DataObject::get_one('HomePage', 'Locale = \'' . Translatable::get_current_locale() . '\'');

This ensures that you get the HomePage of the current locale the user is in. Adding this to the canCreate and getHomePage methods should make this work even for multilingual sites.

Avatar
yurigoul

Community Member, 203 Posts

30 October 2009 at 10:23pm

Thanx very much, this sounds like a jewel! I will play with it and it will probably greatly enhance my understanding of Silverstripe!

Thanks again!

Avatar
Mario...

Community Member, 14 Posts

20 December 2009 at 9:36pm

Helped me out loads, thanks banal:

	public function PageByLang($url, $lang="nb-NO" /*your default lang*/) {
	    $SQL_url = Convert::raw2sql($url);
	    $SQL_lang = Convert::raw2sql($lang);

         $page = DataObject::get_one('FrontPage', 'Locale = \'' . Translatable::get_current_locale() . '\'');
	  

	    if ($page->Locale != Translatable::get_current_locale()) {
	       $page = $page->getTranslation(Translatable::get_current_locale());
	    }
	    return $page;
	}    

Avatar
steve_nyhof

Community Member, 224 Posts

6 January 2010 at 6:08pm

Edited: 06/01/2010 6:10pm

Hi Willr

This is working for me. How can I add an <% if ??? %> to this to find out what page the control is calling?

<% control Page(disclaimer) %>
$Content
<% end_control %>

In my Page.php file I have..

---

class Page_Controller extends ContentController {

function popup() {
return $this->renderWith('PagePopup');
}

---

I then call up a template called PagePopup.ss

mysite.com/disclaimer/popup

When I click on another page, like mysite.com/terms/popup - how can I render the template with the "terms" page $Content?

Go to Top