SilverStripe - Adding Checkbox to CMS
This allows you to add a checkbox to CMS, and then display stuff in the frontend dependant on if it is ticked or not.First you need to add the database field for it.
static $db = array(
'ShowExtraClass' => 'Boolean'
);
Then add the checkbox to the cms
function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldToTab("Root.Content.Main", new CheckboxField ("ShowExtraClass"));
return $fields;
}
And finally you add the if statement in your template:
<% if ShowExtraClass %>
click here for the original website
No comments:
Post a Comment