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've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

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

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

checkbox question (probably very easy one!)


Go to End


3 Posts   1595 Views

Avatar
Hello_electro

Community Member, 80 Posts

13 September 2009 at 9:35am

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;
   }

	
}

Avatar
Willr

Forum Moderator, 5523 Posts

13 September 2009 at 9:49am

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.

Avatar
Hello_electro

Community Member, 80 Posts

13 September 2009 at 10:08am

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