21286 Posts in 5733 Topics by 2602 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 148 Views |
-
Sitetree Inherit data to all pages.

18 March 2013 at 10:55pm Last edited: 19 March 2013 1:51am
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
-
Re: Sitetree Inherit data to all pages.

22 March 2013 at 12:47am
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
| 148 Views | ||
|
Page:
1
|
Go to Top |

