Hi,
I have been using SilverStripe for a couple of years now, and I have decided that I would like to do more with my website and learn a bit more about SS at the same time. I would like to start adding some scripts that I have written to my site. To do this I thought creating a new page type would be the best idea as it allows a bit more flexibility in how the page will be presented.
Each script will have:
- Name
- Language used
- Description of the script - including usage instructions, examples
- Source code
- Download link to zip file of the script and supporting files
I have created the new Page type (see source at the end of my post) and started adding fields to the CMS, but I am having some trouble and need some expert assistance! At this stage I am just focussing on the backend, and have not touched the template for the new page type. The problems I am having are:
1. How do I pre-populate the value of the new fields in the CMS backend?
2. How can I handle a file upload as part of the page edit process? I would prefer to do everything on the one page, rather than upload the file separately and link it manually
3. I remember reading somewhere that Codepress support was added recently. If so, how can I use this for syntax highlighting in my template?
Thanks to anyone that can assist me :)
Source of ScriptPage.php
<?php
/*
Each script will have:
- script name
- language
- Description of script - including usage instructions, examples
- Source code
- Download
*/
class ScriptPage extends Page
{
static $db = array(
'ScriptName' => 'Varchar(20)',
'Language' => "Enum('Powershell', 'Powershell')",
'Description' => 'HTMLText',
'SourceCode' => 'Text',
);
public static $has_one = array( 'SourceZip' => 'File' );
function getCMSFields()
{
$fields = parent::getCMSFields();
$fields->addFieldToTab('Root.Content.Main', new TextField('Script Name'), 'Content');
$fields->addFieldToTab('Root.Content.Main', new DropdownField('Language', 'Language', singleton('ScriptPage')->dbObject('Language')->enumValues()), 'Content');
$fields->addFieldToTab('Root.Content.Main', new HTMLEditorField('Description') , 'Content');
$fields->addFieldToTab('Root.Content.Main', new TextareaField('Source Code') , 'Content');
$fields->addFieldToTab("Root.Content.Main", new FileField('SourceZip'));
return $fields;
}
}
class ScriptPage_Controller extends Page_Controller
{
}
?>