5102 Posts in 1520 Topics by 1116 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 860 Views |
-
Creating a user selection in the backend using TreeDropdownField

16 January 2010 at 12:48am
Hi,
I've got a promotional box on my website and I want to have the ability to select a site from the SiteTree through the backend, where the user will be forwarded to, when clicking on the box (image, text and button). It should be very similar to inserting a link, so I tried to use TreeDropdownField.
My code:
class Box extends Page {
static $db = array();
static $has_one = array(
'Photo' => 'Image',
'TargetContent' => 'SiteTree'
);
function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldToTab("Root.Content.Main", new TreeDropdownField("TargetContentID", "Choose a site to be forwarded to:", "SiteTree"));
$fields->addFieldToTab("Root.Content.Photo", new ImageField('Photo'));
return $fields;
}
}class Box_Controller extends Page_Controller {}
Now I already get the correct page ID, but no idea how to handle this :-?
How do I get the URL of the page ID now and how can I filter the SiteTree that will be displayed in the dropdown?
Thanks for any help in advance!
Cheers, Mario
-
Re: Creating a user selection in the backend using TreeDropdownField

16 January 2010 at 5:16pm
Well to get the various properties of the TargetContent you use the built in ORM. Since you have a has_one relationship between your box and your TargetContent you can get the full TargetContent object using $TargetContent in the template or $this->TargetContent() in the PHP code.
Since you have the object you can then call all the usual SiteTree methods on them. Eg to get the URL in the template
<% if TargetContent %>$TargetContent.Link<% end_if %>
-
Re: Creating a user selection in the backend using TreeDropdownField

17 January 2010 at 1:07am Last edited: 17 January 2010 1:08am
I'm sure I did try that, but now it works perfect... maybe I was drunk ;-)
Thanks for the help!
What about filtering the DropDown in the backend?
| 860 Views | ||
|
Page:
1
|
Go to Top |


