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   861 Views

Avatar
pinkp

4 September 2009 at 9:48pm (Last edited: 4 September 2009 9:48pm), Community Member, 168 Posts

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

4 September 2009 at 11:17pm (Last edited: 4 September 2009 11:20pm), Community Member, 271 Posts

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

6 September 2009 at 9:29pm (Last edited: 6 September 2009 9:31pm), Community Member, 168 Posts

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

11 September 2009 at 7:45am Community Member, 85 Posts

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

11 September 2009 at 10:25am Community Member, 168 Posts

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