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're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

Template Questions /

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

Get value of DropdownField not the ID

Go to End

3 Posts   1492 Views


Community Member, 6 Posts

23 March 2014 at 1:21pm


in the page.php I have this code:

	private static $db = array(
                'Glasart' => 'Text'

and this:

public function getCMSFields() {
        $fields = parent::getCMSFields();
        $options = array("Kaffeeglas", "Weinglas", "Cocktailglas", "Bierglas", "Sektglas", "Wasserglas", "Sonstige"); 
        $fields->addFieldToTab("Root.Main", new DropdownField("Glasart", "Glasart", $options), 'Content');
        return $fields;

and in the

       <h1>$Title - $Glasart</h1>

But in the frontend I only see the ID of the selected value, but I want the value, for example "Kaffeglas".
Any ideas ? :-)


Forum Moderator, 5523 Posts

23 March 2014 at 5:54pm

Your array should look something like this then
"Kaffeeglas" => "Kaffeeglas",
"Weinglas" => "Weinglas"

If you don't want to write the same thing twice, you could use array_combine to generate that for you ($a = array_combine($a, $a))


Community Member, 6 Posts

25 March 2014 at 12:06am

Thanks! That worked just fine :-)