Hi there,
I've been trying to add a dropdown to my CMS that allows the user to create a link to a page on the site. Rather than expect them to "hardcode" (copy & paste in) the URL of their chosen page, I had loaded the siteTree into a TreeMultiSelectField.
I've put the main extract of the code at the base of my post.
It "works" in the CMS so far as that all the site pages load into the dropdown, you can select one and then save it.
However, when I then call the item on the template ($ChooseURL1) the output I get back is as follows:
<ul id="Menu1">
<li onclick="location.href = this.getElementsByTagName('a')[0].href"><a href="">Budgeting and Planning</a></li>
</ul>
However, what I actually want is the URL to the chosen page. (Crossed fingers and tried "$ChooseURL1.URL" but it didn't work!)
Hoping someone can help. Many thanks x
on HomePage.php:
...
static $db = array(
'ServiceTitle1' => 'Text',
'ServiceCopy1' => 'Text',
'UseIcon1' => "Enum('Globe,Whiteboard,Other', '')"
);
static $has_one = array(
);
public static $many_many = array(
'ChooseURL1' => 'SiteTree'
);
...
function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldToTab('Root.Content.ServiceBoxes', new TextField('ServiceTitle1'), '');
$fields->addFieldToTab('Root.Content.ServiceBoxes', new TextField('ServiceCopy1'), '');
$fields->addFieldToTab('Root.Content.ServiceBoxes', new TreeMultiSelectField('ChooseURL1','Choose page,'SiteTree'));
$fields -> addFieldtoTab('Root.Content.ServiceBoxes', new DropdownField('UseIcon1', 'Select icon', $this->dbObject('UseIcon1')->enumValues()));
return $fields;
}