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:

Data Model Questions /

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

CheckboxSetField , how to display data in template ?


Go to End


3 Posts   2172 Views

Avatar
snaip

Community Member, 181 Posts

13 April 2010 at 8:52pm

Edited: 13/04/2010 8:53pm

hi

in CMS i have


static $has_many = array(
	'WyroznioneProdukty' => 'SiteTree'
);
...

function getCMSFields() {
$fields = parent::getCMSFields();

$KrakowProduktList = DataObject::get('KrakowProdukt');
$fields->addFieldToTab("Root.Content.WyroznijNaStronieKategorii",new CheckboxSetField('WyroznioneProdukty','Select all related pages to appear in the main page', $KrakowProduktList)); 		

return $fields;
}

now how to display checked elements in CheckboxSetField in templetes ?

i tried to

<% control WyroznioneProdukty %>
<p>$Title</p>
<% end_control %> 		

but it displays all elements which are in the CheckboxSetField (checked and unchecked)

Avatar
Willr

Forum Moderator, 5523 Posts

13 April 2010 at 10:21pm

The has_many should only return the saved options. Do you have a has one relationship on the other side? (Has many must has a related has one).

Avatar
snaip

Community Member, 181 Posts

13 April 2010 at 10:40pm

this is all my code


<?php
 
class Krakow extends SiteTree {

	static $db = array(
		'SG1Brak' => "Boolean",
		'SG2Brak' => "Boolean",
		'SG3Brak' => "Boolean"	
	);
	
	static $has_one = array(
		'SG1' => 'SiteTree',
		'SG2' => 'SiteTree',
		'SG3' => 'SiteTree',
		'StronaGlowna' => 'StronaGlowna'
	);
	
	static $has_many = array(

		'WyroznioneProdukty' => 'SiteTree'
	);
	
	static $allowed_children = array('KrakowProdukt');

	function getCMSFields() {
		$fields = parent::getCMSFields();		

		$KrakowProduktList = DataObject::get('KrakowProdukt');

		
		$fields->addFieldToTab("Root.Content.PromujNaStronieGlownej", new TreeDropdownField('SG1ID','Produkt pierwszy:','SiteTree')); 
		$fields->addFieldToTab("Root.Content.PromujNaStronieGlownej", new CheckboxField('SG1Brak','Wyświetl ten element'));
		$fields->addFieldToTab("Root.Content.PromujNaStronieGlownej", new TreeDropdownField('SG2ID','Produkt drugi:','SiteTree'));
		$fields->addFieldToTab("Root.Content.PromujNaStronieGlownej", new CheckboxField('SG2Brak','Wyświetl ten element')); 
		$fields->addFieldToTab("Root.Content.PromujNaStronieGlownej", new TreeDropdownField('SG3ID','Produkt trzeci:','SiteTree'));
		$fields->addFieldToTab("Root.Content.PromujNaStronieGlownej", new CheckboxField('SG3Brak','Wyświetl ten element')); 	

		$fields->addFieldToTab("Root.Content.WyroznijNaStronieKategorii",new CheckboxSetField('WyroznioneProdukty','Select all related pages to appear in the right column', $KrakowProduktList)); 		

		
		return $fields;
	}

}
 
class Krakow_Controller extends Strona_Controller { 

 
} 
?>