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

CMS Fields for a specific page


Go to End


5 Posts   1058 Views

Avatar
clauddiu

Community Member, 5 Posts

12 May 2012 at 5:14pm

Hello,

I'm new here, my name is Claudiu, guys, I have read lots of pages about how to add fields to cms, so far I try this code:

<?php

	class Furniture extends Page {

		public static $db = array(
			'TestField'=> 'Text'
		);

		public static $has_one = array(
		);

	    function getCMSFields() {
	        $fields = parent::getCMSFields();
	        $fields->addFieldToTab('Root.Content.Main', new TextField('TestField'), 'Content');
	        return $fields;
	    }
	}

	class Furniture_Controller extends ContentController {}


 ?>

So I have this page called Furniture and I cant find a way to add that field to that page only, can anyone give me a hint how to do it, please?

Ciao,
Claudiu

Avatar
Webdoc

Community Member, 349 Posts

12 May 2012 at 8:06pm

to get the field to web use in themes/yourtheme/layout/Furniture.ss

<div class="typography">
	<% if Menu(2) %>
		<% include SideBar %>
		<div id="Content">
	<% end_if %>

	<% if Level(2) %>
	  	<% include BreadCrumbs %>
	<% end_if %>
	
		<h2>$Title</h2>
	
		$Content
<% if TestField %>
$TestField
<% end_if %>
		$Form
		$PageComments
	<% if Menu(2) %>
		</div>
	<% end_if %>
</div>

Avatar
clauddiu

Community Member, 5 Posts

12 May 2012 at 8:09pm

Thank you for your reply, I want to add fields to admin cms, like have custom field before or after the content for this furniture page.
Is there a way to do it ?

Thank you,
Claudiu

Avatar
Webdoc

Community Member, 349 Posts

12 May 2012 at 8:13pm

your field is added already. Did u use http://www.yoursitenane.com/dev/build?flush=1
do make it work

Avatar
clauddiu

Community Member, 5 Posts

12 May 2012 at 8:21pm

Edited: 12/05/2012 8:24pm

Yes, but is not working, this is what I did for last 4 hours..
So I have this page FURNITURE uppercase, when I need to add fields into admin panel for this page, is the code I paste before I need to write something else?

Because, I added same code to Page.php where the Page extends SiteTree and worked, but added that field to all pages and I need to only one to add some more fields.

Thank you,
Claudiu