17488 Posts in 4473 Topics by 1978 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 4274 Views |
-
Loading other page content into a sidebar content area?

10 July 2008 at 3:58am Last edited: 10 July 2008 3:59am
I have my main content area and I also have two sidebar content areas. I want to know if I can load another pages content (reuse) into one or both of the sidebars using TreeDropdownField?
Right now I am trying this,
<?php
class Page extends SiteTree {
static $db = array(
'LeftSide' => 'HTMLText',
'RightSide' => 'HTMLText'
);
function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldToTab('Root.Content.Main', new TreeDropdownField("LeftSide", "Choose a page to appear in the left sidebar:", "SiteTree"));
$fields->addFieldToTab('Root.Content.Main', new TreeDropdownField("RightSide", "Choose a page to appear in the right sidebar:", "SiteTree"));
return $fields;
}
static $has_one = array(
);
}This just returns the page id in the sidebar instead of the actual page HTML.
Am I way off? Is this even possible.
Thanks in advance!
-Aaron
-
Re: Loading other page content into a sidebar content area?

10 July 2008 at 9:30am Last edited: 10 July 2008 9:36am
First of all - a test - I just wrote a long response and the forum totally bailed on submission...
...ok that really sucks. Here goes again:
Store those numbers as Ints - we'll use them later:
class Page extends SiteTree {
static $db = array('LeftSide' => 'Int',
'RightSide' => 'Int'
);
}Now you can create a couple of customer getters to retrieve the pages you want:
class Page extends SiteTree {
...
function RightPage() {
return DataObject::get_by_id("Page", $this->RightSide);
}
function LeftPage() {
return DataObject::get_by_id("Page", $this->LeftSide);
}
}Now, within your side bar .SS template files (or wherever you want, really) you can control those pages:
<% control RightPage %>
<h3>$Title</h3>
$Content
<% end_control %>This is totally untested, but it should get you on the right track!
-
Re: Loading other page content into a sidebar content area?

10 July 2008 at 9:40am
Why not store those numbers as has_one's?
static $has_one = array(
'LeftSide' => 'Page',
'RightSide' => 'Page'
);Then, in the template you can do:
<% control LeftSide %>
<h3>$Title</h3>
$Content
<% end_control %><% control RightSide %>
<h3>$Title</h3>
$Content
<% end_control %>without the need to make those extra getter methods.. I think
-
Re: Loading other page content into a sidebar content area?

10 July 2008 at 9:54am Last edited: 10 July 2008 9:54am
:-0
Sometimes I forget how easy Silverstripe makes this sort of thing sometimes.
For my own peace of mind, the two are functionally equivalent though, right? The has_one relationship will store the page ID and get the dataobject automatically?
-
Re: Loading other page content into a sidebar content area?

10 July 2008 at 1:50pm
Thanks guys!
I will try this right away!
-Aaron
-
Re: Loading other page content into a sidebar content area?

10 July 2008 at 2:18pm
Hey Hamish,
Your method worked great!
This is HUGE! Thank you!
-Aaron
-
Re: Loading other page content into a sidebar content area?

11 July 2008 at 11:10am
ok I am confused
would I need to download tree control to understand a bit better
what you guys are talking about? -
Re: Loading other page content into a sidebar content area?

5 September 2008 at 12:41pm
Hi there!
I logically understand what you are talking about but pratically I can't realize it on my own...
Where to pass these code-snippets and how to set the page I want to display in the sidebar!?I passed the code in mysite/code/Page.php - is this the right place?
Where to set that the page thaht should be displayed e.g. "id=contact"?I'm new to ss and php so please be patient...
Thanks Berny
| 4274 Views | ||
|
Page:
1
|
Go to Top |



