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.

Customising the CMS /

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

CheckBox in Admin Area

Go to End

4 Posts   9849 Views


Community Member, 17 Posts

4 January 2009 at 12:29pm


I would like to create a checkbox in my admin area for my client to indicate whether an item in her online gallery has been sold or not. If an item is sold, then I have a little extra HTML to insert in the page ("SOLD. This item has been sold and is available for viewing only.").

I know how to create images and text fields in the CMS, but how to create a checkbox?
And then how do I call an "if" statement on the checkbox in my template page? Would I need to write a function to query the state of the checkbox or can I check its value in the database directly?


Carbon Crayon

Community Member, 598 Posts

4 January 2009 at 3:15pm

Edited: 04/01/2009 3:18pm

Hi Boogiez, welcome to Silverstripe

I would recommend you do the tutorials to start with, they give you a very good introduction to how both the templates and admin/db work. You can find them here:

To answer your question you can easily add a checkbox to a page in the admin by adding this to your Page.php file:

class Page extends SiteTree {
       static $db = array(
                'CheckboxValue' => 'Boolean'

	function getCMSFields() {
	$fields = parent::getCMSFields();
	$fields->addFieldToTab("Root.Content.Main", new CheckboxField ("CheckboxValue"));
	return $fields;	

then in your template you simply do this:

<% if CheckboxValue %>
<% end_if %>

Hope that helps :)


Community Member, 17 Posts

5 January 2009 at 8:33am

Thanks very much aram! Works like a charm. I checked the tutorials but I didn't see how to create a checkbox. Do you know if there's a page that lists all of the controls we can offer in the CMS?

Carbon Crayon

Community Member, 598 Posts

5 January 2009 at 8:51am

yep, check these pages out, I found them very useful when I started and still refer to them often:

Form types:

Built in page controls:


Recipies (various how too's):

I think the tutorials are invaluable if you want to start developing sites in SS beacuse they give you a really good introduction to how it all works and so once you have done them you can really start descovering the beauty of SS (with the help of the docs and forum of course)

Anyway good luck and hope to see you around the forums :)