Jump to:

5513 Posts in 1732 Topics by 1218 members

Customising the CMS

SilverStripe Forums » Customising the CMS » Help with custom page; make array and tags

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

Page: 1
Go to End
Author Topic: 1237 Views
  • raamklaza
    Avatar
    Community Member
    182 Posts

    Help with custom page; make array and tags Link to this post

    I have the following GamesPage...

    1. How can i make the Tags display like on the Blog? When you put a comma between them that they are seperated? And that you can click them? I guess i need a GamesTagesPage for this but how do i do this?

    2. Category, i want this to be a fixed selection (like: category 1, category 2, category 3) how do i do this?

    <?php
    /**
    * Defines the GamesPage page type
    */
    class GamesPage extends Page {
    static $db = array(
    'Category' => 'Text',
        'Tags' => 'Text',
        'Description' => 'Text',
        'Instructions' => 'Text'
    );
    static $has_one = array(
        'Photo' => 'Image'
    );

    function getCMSFields() {
    $fields = parent::getCMSFields();

    $fields->addFieldToTab('Root.Content.Main', new Textfield('Category'), 'Content');
    $fields->addFieldToTab('Root.Content.Main', new TextField('Tags'), 'Content');
    $fields->addFieldToTab('Root.Content.Main', new TextField('Description'), 'Content');
    $fields->addFieldToTab('Root.Content.Main', new TextField('Instructions'), 'Content');
    $fields->addFieldToTab('Root.Content.Images', new ImageField('Photo'));
       
       return $fields;
    }
       static $icon = "themes/Vista/images/treeicons/games";
       
       static $defaults = array(
          'ProvideComments' => true
          );

    }

    class GamesPage_Controller extends Page_Controller {

    }

    ?>

  • raamklaza
    Avatar
    Community Member
    182 Posts

    Re: Help with custom page; make array and tags Link to this post

    Anyone?

  • theAlien
    Avatar
    Community Member
    131 Posts

    Re: Help with custom page; make array and tags Link to this post

    1. Look into the blogmodule. Reading lines 92-110 in BlogEntry.php, TagCloudWidget.ss and lines 8-15 in BlogEntry.ss will learn you alot.
    2. I don't really understand what you want to do. But you might want to look here: http://doc.silverstripe.org/doku.php?id=form-field-types and try something with CheckboxSetField, OptionSetField and DropdownField.

  • raamklaza
    Avatar
    Community Member
    182 Posts

    Re: Help with custom page; make array and tags Link to this post

    I want to have a dropdownmenu for category in the cms.

    I will look into the links you've send me, thnx.

  • raamklaza
    Avatar
    Community Member
    182 Posts

    Re: Help with custom page; make array and tags Link to this post

    Oke That's gone work!

    2 more questions though about the same first post ;)

    1. How can i make the field with "Instructions" have more lines? I tried something with: http://doc.silverstripe.org/doku.php?id=textareafield but that didn't work at all...

    2. How can i show my Categories on a GamesHolder.ss page? So that the are clickable aswell? So first a summary and then you can click on them

    New GamesHolder.php

    <?php
    /**
    * Defines the GamesPage page type
    */
    class GamesPage extends Page {
    static $db = array(
    'Category' => 'Varchar(100)',
        'Tags' => 'Text',
        'Description' => 'Text',
        'Instructions' => 'Text'
    );
    static $has_one = array(
        'Photo' => 'Image'
    );

    function getCMSFields() {
    $fields = parent::getCMSFields();

       // Category Array
       $array = array(
        'Klassiekers' => 'Klassiekers',
        'US' => 'United States',
        'US' => 'United States',
        'US' => 'United States',
        'US' => 'United States',
        'US' => 'United States',
        'US' => 'United States'
       );

    $fields->addFieldToTab('Root.Content.Main', new DropdownField('Category', 'Category', $array), 'Content');
    $fields->addFieldToTab('Root.Content.Main', new TextField('Tags', 'Tags (comma sep.)'), 'Content');
    $fields->addFieldToTab('Root.Content.Main', new TextField('Description'), 'Content');
    $fields->addFieldToTab('Root.Content.Main', new TextField('Instructions'), 'Content');
    $fields->addFieldToTab('Root.Content.Images', new ImageField('Photo'));
       
       return $fields;
    }

       /**
        * Returns the tags added to this games entry
        */
       function TagsCollection() {
          $tags = split(" *, *", trim($this->Tags));
          $output = new DataObjectSet();
          
          foreach($tags as $tag) {
             $output->push(new ArrayData(array(
                'Tag' => $tag,
                'Link' => $this->getParent()->Link() . 'tag/' . urlencode($tag)
             )));
          }
          
          if($this->Tags) {
             return $output;
          }
       }

       static $icon = "themes/Vista/images/treeicons/games";
       
       static $defaults = array(
          'ProvideComments' => true
          );

    }

    class GamesPage_Controller extends Page_Controller {

    }

    ?>

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