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

retrieving cms field in function


Go to End


2 Posts   795 Views

Avatar
servalman

Community Member, 211 Posts

1 March 2011 at 5:57am

Hello

I'm trying to retrieve the value of a cms field inside a function but it does't work

In code.php

class SomeClassPage extends Page{
	
	static $db = array(
		'AutorizedContent'	=> 'HTMLText',
		'ForbidenContent'	=> 'HTMLText'
	);
	

	
	

	function getCMSFields(){
		$f = parent::getCMSFields();
		$f->addFieldToTab('Root.Content.AutorizedContent', new HTMLEditorField('AutorizedContent'));
		$f->addFieldToTab('Root.Content.ForbidenContent', new HTMLEditorField('ForbidenContent'));
		return $f;
	}

then I have

class SomeClassPage_Controller extends Page_Controller{
	

	

	
	
	function Authorise(){

		
								return $this->ForbidenContent;
							}
						

in template

<% if Authorise %> $ForbidenContent<% end_if %>

Any idea

thanks

Avatar
swaiba

Forum Moderator, 1899 Posts

1 March 2011 at 6:03am

try this in template

<% if Authorise %> <% control Authorise %> $ForbidenContent<% end_control %><% end_if %>