Jump to:

3461 Posts in 1065 Topics by 740 members

Data Model Questions

SilverStripe Forums » Data Model Questions » CheckboxSetField , how to display data in template ?

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

Page: 1
Go to End
Author Topic: 1834 Views
  • snaip
    Avatar
    Community Member
    180 Posts

    CheckboxSetField , how to display data in template ? Link to this post

    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)

  • Willr
    Avatar
    Forum Moderator
    5511 Posts

    Re: CheckboxSetField , how to display data in template ? Link to this post

    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).

  • snaip
    Avatar
    Community Member
    180 Posts

    Re: CheckboxSetField , how to display data in template ? Link to this post

    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 {

    }
    ?>

    1834 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.