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.

Customising the CMS /

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

Help with custom page; make array and tags


Go to End


5 Posts   1797 Views

Avatar
raamklaza

Community Member, 182 Posts

8 July 2009 at 8:54am

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 {
 
}
 
?>

Avatar
raamklaza

Community Member, 182 Posts

10 July 2009 at 3:36am

Anyone?

Avatar
theAlien

Community Member, 131 Posts

13 July 2009 at 11:50am

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.

Avatar
raamklaza

Community Member, 182 Posts

13 July 2009 at 8:37pm

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

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

Avatar
raamklaza

Community Member, 182 Posts

14 July 2009 at 7:41am

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 {
 
}
 
?>