In SilverStripe 3.1 I'm trying to get the value of my Hello Bar selector to be accessible by pages site wide.
I've created the dropdown field to select the contents on the HomePage.php
so I'm having no problem referencing the fields value on the home page. The value of the dropdown will inform the if block to run and what to populate the hello bar with.
Page.php
..//
public function HelloBarSelector() {
$Selector = HomePage::get()->HelloBarSelect;
return $Selector;
}
public function ShowHelloBar($itemID = 1) {
$HelloBars = HelloBar::get()->byID($itemID);
$HelloBars = $HelloBars->HelloBarText;
return $HelloBars;
}
..//
Includes/HelloBar.ss
<% if $HelloBarSelector %>
<section class="hello">
<p class="hello__text">$ShowHelloBar($HelloBarSelector)</p>
</section>
<% end_if %>
HomePage.php
..//
public function getCMSFields(){
$fields = parent::getCMSFields();
$fields->addFieldToTab('Root.HelloBar', GridField::create(
'HelloBars',
'Hello Bar Text',
$this->HelloBars(),
GridFieldConfig_RecordEditor::create()
));
$fields->addFieldToTab('Root.HelloBar', DropdownField::create(
'HelloBarSelect',
'Choose Your Hello Bar (this will be sitewide)',
HelloBar::get()->map('ID', 'HelloBarText')
)
->setEmptyString('(none)'));
return $fields;
}
..//
I have no issues accessing the value with $HelloBarSelect
on the home page and all works as expected. It seems the problem is accessing the $HelloBarSelect
with my function.