Jump to:

23012 Posts in 11539 Topics by 2825 members

General Questions

SilverStripe Forums » General Questions » CMS Fields for a specific page

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: 421 Views
  • clauddiu
    Avatar
    Community Member
    5 Posts

    CMS Fields for a specific page Link to this post

    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

  • Webdoc
    Avatar
    Community Member
    329 Posts

    Re: CMS Fields for a specific page Link to this post

    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>

  • clauddiu
    Avatar
    Community Member
    5 Posts

    Re: CMS Fields for a specific page Link to this post

    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

  • Webdoc
    Avatar
    Community Member
    329 Posts

    Re: CMS Fields for a specific page Link to this post

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

  • clauddiu
    Avatar
    Community Member
    5 Posts

    Re: CMS Fields for a specific page Link to this post

    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

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