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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

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

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

Sitetree Inherit data to all pages.


Go to End


4 Posts   1270 Views

Avatar
Juan

Community Member, 18 Posts

18 March 2013 at 10:55pm

Edited: 19/03/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 :)

Avatar
Juan

Community Member, 18 Posts

19 March 2013 at 2:50pm

any help? :|

Avatar
Juan

Community Member, 18 Posts

20 March 2013 at 8:35pm

UP

Avatar
El Mich

Community Member, 8 Posts

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