Jump to:

22977 Posts in 11806 Topics by 2826 members

General Questions

SilverStripe Forums » General Questions » checkbox question (probably very easy one!)

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Page: 1
Go to End
Author Topic: 1019 Views
  • Hello_electro
    Avatar
    Community Member
    80 Posts

    checkbox question (probably very easy one!) Link to this post

    I have an image I am using on my home page that is controlled form the Image tab on my CMS for that page. I added treedropdown field and then a checkbox to note if the user wants the selected page to be a link or not.

    I cant get the checkbox to control the IF statement. Do i need to do something else in the IF statement, like note a value or something? right now the IF staement makes the DonatePhotoLink div appear all the time no matter the checkbox state. Thanks in advance!

    page.ss

    <div id="DonateImageHome">
                <div id="DonatePhotoHome">$Photo</div>
                <% if ActivateLink %><div id="DonatePhotoLink">&nbsp;</div><% end_if %>
             </div>

    page.php

    class Page extends SiteTree {
       static $db = array(
       );
        static $has_one = array(
    'Photo' => 'Image',
        'MainImageLink' => 'SiteTree',
        'ActivateLink' => 'Boolean'
       
    );
       

    function getCMSFields() {
    $fields = parent::getCMSFields();
    $fields->addFieldToTab("Root.Content.Images", new ImageField("Photo"));
       $fields->addFieldToTab('Root.Content.Images', new TreeDropdownField('MainImageLinkID', 'Link image to', 'SiteTree'));
       $fields->addFieldToTab('Root.Content.Images', new CheckboxField ('ActivateLink'));
    return $fields;
    }

       
    }

  • Willr
    Avatar
    Forum Moderator
    5462 Posts

    Re: checkbox question (probably very easy one!) Link to this post

    The 'ActivateLink' => 'Boolean' should be in the $db array, not the has_one array. Move that and run dev/build again, select the checkbox again in the cms, save and that should fix it.

  • Hello_electro
    Avatar
    Community Member
    80 Posts

    Re: checkbox question (probably very easy one!) Link to this post

    That did it! Cheers. and for me...Doh!

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