Jump to:

23359 Posts in 18096 Topics by 2862 members

General Questions

SilverStripe Forums » General Questions » Sitetree Inherit data to all pages.

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Page: 1
Go to End
Author Topic: 360 Views
  • Juan
    Avatar
    Community Member
    18 Posts

    Sitetree Inherit data to all pages. Link to this post

    I've edited the page.php to this

    class Page extends SiteTree {

       static $db = array(

          'LinkPage' => 'Text'
       );
       
        static $has_one = array(
           'LinkImage' => 'Image',
           'LinkToSiteTree' => 'SiteTree'

       );
    .
    .
    .
    function getCMSFields() {
          $fields = parent::getCMSFields();
          

          $fields->addFieldToTab('Root.Content.HeaderImageBanner', new TextField("LinkPage", "Link (e.g. http://example.com)"));
          $fields->addFieldToTab('Root.Content.HeaderImageBanner', new HeaderImageBannerField("LinkImageID","Image to display (from assest uploaded to 'widgets' folder)"));

          

          return $fields;
       }

    .
    .
    .
       public function getLinkToPage() {
          $strURL = '';
          if (!empty($this->LinkPage)) {
             $strURL = $this->LinkPage;
             if (!strpos($strURL, 'http') === 0) {
                $strURL = $this->BaseHref().$strURL;
             }
          }
          else {
             if (isset($this->LinkToSiteTreeID) && is_numeric($this->LinkToSiteTreeID)) {
                $page = DataObject::get_by_id('SiteTree',$this->LinkToSiteTreeID);
                if ($page) {
                   $strURL = $this->BaseHref().$page->RelativeLink();
                }
             }
          }

          return $strURL;
       }

       function getLinkImageTag() {
          if (isset($this->LinkImageID) && is_numeric($this->LinkImageID)) {
             return DataObject::get_by_id('Image',$this->LinkImageID);
          }
          return null;
       }

    what it does it will save the image link and the image.

    my question is how can i inherit its output to all pages of my site? (header)

    I'm using SS 2.4

    Thank you in advance

  • Juan
    Avatar
    Community Member
    18 Posts

    Re: Sitetree Inherit data to all pages. Link to this post

    any help? :|

  • Juan
    Avatar
    Community Member
    18 Posts

    Re: Sitetree Inherit data to all pages. Link to this post

    UP

  • El Mich
    Avatar
    Community Member
    8 Posts

    Re: Sitetree Inherit data to all pages. Link to this post

    Hi Juan,
    maybe try this:
    http://www.ssbits.com/tutorials/2010/2-4-working-with-siteconfig/
    especially the paragraph about extending the siteconfig object by decorator.
    Good luck,
    Mich

    360 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.