Skip to content
Nathan Cox edited this page Aug 14, 2013 · 3 revisions

This is the start of a SilverStripe 3 module for creating radio button fields with a more custom appearance.

At the moment it's only tested with images in place of radio buttons/labels but will ideally take whole HTML blocks.

Example Usage

<?php
// in getCMSFields
		// set up a field to pick an icon for this page
		$icons = array(
			'user',
			'user-female',
			'user-white',
			'user-white-female',
			'user-yellow',
			'user-yellow-female',
			'user-green',
			'user-green-female'
		);

		$makeOption = function($iconName) {
			return "<img src='mysite/images/treeicons/" . $iconName . ".png' alt='' />";
		};

		$options = array();
		foreach($icons as $iconName) {
			$options[$iconName] = $makeOption($iconName);
		}

		$fields->addFieldtoTab('Root.Settings', $iconField = new HTMLOptionsetField(
			'Icon', 
			'Tree icon',
			$options
		));

Result:

HTMLOptionSetField example 1

Note: Icons are from the Fugue icon set (http://p.yusukekamiyamane.com/).

Clone this wiki locally