Jump to:

3439 Posts in 1028 Topics by 869 members

Template Questions

SilverStripe Forums » Template Questions » How to: Same info on every page, edit from one source by user?

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

Page: 1
Go to End
Author Topic: 856 Views
  • pinkp
    Avatar
    Community Member
    168 Posts

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

    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

  • Martijn
    Avatar
    Community Member
    271 Posts

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

    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.

  • pinkp
    Avatar
    Community Member
    168 Posts

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

    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

  • Samba Sam
    Avatar
    Community Member
    85 Posts

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

    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

  • pinkp
    Avatar
    Community Member
    168 Posts

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

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

    856 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.