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.

Template Questions /

How to: Same info on every page, edit from one source by user?


Reply


5 Posts   875 Views

Avatar
pinkp

Community Member, 168 Posts

4 September 2009 at 9:48pm

Edited: 04/09/2009 9:48pm

I'm sure this is prob quite simple but as a noob I can't figure it out.

I need contact info (call now on: blah) on all pages with the Page PageType.
I want it to come from a single source so it only needs changing once.
I also need it to be editable in the CMS by the user?

What is the best way to produce this please?
All help appreciated! Thanks :)

Avatar
Martijn

Community Member, 271 Posts

4 September 2009 at 11:17pm

Edited: 04/09/2009 11:20pm

Create a ContactPage pagetype to admin the contactdetails.

To ensure you only have one contactpage add:

function canCreate() {
      if(DataObject::get_one('ContactPage')) {
         return false;
      } else {
         return true;
      }
   }

In Page_Controller add

public function ContactDetails() {
      if(class_exists("ContactPage")) return DataObject::get_one("ContactPage");
   }

in template use control ContactDetails to display the info.

Avatar
pinkp

Community Member, 168 Posts

6 September 2009 at 9:29pm

Edited: 06/09/2009 9:31pm

Hi could you please give me some more help, I'm really new to this and haven't managed to get this to work.

I've created a new PageType = ContactPage.php in mysite/code

<?php
/**
* Defines the ContactPage page type
*/
class ContactPage extends Page {
static $db = array(
);
static $has_one = array(
);

}

class ContactPage_Controller extends Page_Controller {

public function ContactDetails() {
if(class_exists("ContactPage")) return DataObject::get_one("ContactPage");
}

}

function canCreate() {
if(DataObject::get_one('ContactPage')) {
return false;
} else {
return true;
}
}

?>

I'm not sure if this is correct?

This new PageType is then in the CMS (after Flush) and I've made a ContactPage with the details on.

Then called it in the the main template (Page.ss) like so:

<div id="content">
$Layout
$ContactDetails
</div>

I'm then expecting the ContactPage from the CMS to display its info at the bottom of every page..??
Help appreciated? Thanks

Avatar
Samba Sam

Community Member, 85 Posts

11 September 2009 at 7:45am

You may want to take a look at the following thread. It is a little different, in that it explains how to display footer information entered on one page in the CMS, in this case in the homepage on all pages. But the homepage could be easily changed to any page.

Dynamic Footer
http://silverstripe.org/general-questions/show/260690#post260690

Hope it helps,
Sam

Avatar
pinkp

Community Member, 168 Posts

11 September 2009 at 10:25am

Thanks for the link! Sounds good, I'll try it out! nice one Happy Sadhu :)