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.

Archive /

Our old forums are still available as a read-only archive.

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

I'm confused...Could someone help me if they aren't busy?


Reply


3 Posts   1312 Views

Avatar
Ghostdemon

Community Member, 2 Posts

21 July 2008 at 5:25pm

Edited: 21/07/2008 5:56pm

Ok I also have just downloaded Silverstripe and let me say it is THE best site maker I have used. Anyway on to the prolem which is changing the Name of the site and Tagline. Someone else had a problem but the reply was confusing to me. How can I change the name and tagline from the CMS? Please help. Oh and I just notice I posted this in the wrong section. Sorry about that

Avatar
Sean

Forum Moderator, 922 Posts

21 July 2008 at 7:06pm

Edited: 21/07/2008 7:12pm

1. First of all, create a special page type called HomePage - do this by creating a new file called HomePage.php inside mysite/code - this should be familiar if you've gone through the first two tutorials.

2. Create the HomePage extends Page class, as well as the HomePage_Controller extends Page_Controller class in the HomePage.php file.

3. Create two data fields on the HomePage class, that will be stored in the database. These will be the site name, as well as the tag line. We also create the form fields so you can edit the value in the CMS using getCMSFields() e.g.

class HomePage extends Page {

   static $db = array(
      'SiteName' => 'Varchar(100)',
      'Tagline' => 'Varchar(100)'
   );

   function getCMSFields() {
      $fields = parent::getCMSFields();
      $fields->addFieldToTab('Root.Content.Main', new TextField('SiteName', 'Name of site'));
      $fields->addFieldToTab('Root.Content.Main', new TextField('Tagline', 'Tagline of site'));

      return $fields;
   }

}
class HomePage_Controller extends Page_Controller {

}

4. Run db/build?flush=1, and in the CMS, make sure the "Home" page has the page type "Home Page" (see the Behaviour tab whilst on the page.

5. Open up Page.php, and add two functions. These functions take an instance of HomePage and return the SiteName and Tagline data fields, assuming you'll only ever have one home page. e.g.

class Page extends SiteTree {

   function SiteName() {
      $homePage = DataObject::get_one('HomePage');
      return $homePage ? $homePage->SiteName : false;
   }

   function Tagline() {
      $homePage = DataObject::get_one('HomePage');
      return $homePage ? $homePage->Tagline : false;
   }

}
class Page_Controller extends ContentController {

}

6. Open up themes/blackcandy/templates/Page.ss and look for "Your Site Name". Replace that text with $SiteName.

7. Do the same as 6), looking for "Your site's tagline here", replacing it with $Tagline

I'll probably add this to the wiki if there's not already a recipe on there for doing this.

Hope this helps!

Cheers,
Sean

Avatar
Willr

Forum Moderator, 5513 Posts

23 July 2008 at 5:38pm

or if you dont need to edit the Site name from the CMS (this is currently not supported - you have to edit the template file)

Open themes/ the theme name /templates/Page.ss in a text editor (eg Notepad) and edit the Your Site Name String