Jump to:

5521 Posts in 1733 Topics by 1220 members

Customising the CMS

SilverStripe Forums » Customising the CMS » CheckBox in Admin Area

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

Page: 1
Go to End
Author Topic: 5300 Views
  • Boogiez
    Avatar
    Community Member
    17 Posts

    CheckBox in Admin Area Link to this post

    Hi,

    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?

    Thanks,
    Mark

  • Aram
    Avatar
    Community Member
    598 Posts

    Re: CheckBox in Admin Area Link to this post

    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: http://doc.silverstripe.com/doku.php

    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 %>
    <p>SOLD</p>
    <% end_if %>

    Hope that helps

  • Boogiez
    Avatar
    Community Member
    17 Posts

    Re: CheckBox in Admin Area Link to this post

    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?

  • Aram
    Avatar
    Community Member
    598 Posts

    Re: CheckBox in Admin Area Link to this post

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

    Form types: http://doc.silverstripe.com/doku.php?id=form-field-types

    Built in page controls: http://doc.silverstripe.com/doku.php?id=built-in-page-controls

    DataModel: http://doc.silverstripe.com/doku.php?id=datamodel

    Recipies (various how too's): http://doc.silverstripe.com/doku.php?id=recipes:start

    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

    5300 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.