Resources: SilverStripe

Being a web designer/developer from Wellington, and given the ‘support local businesses’ attitude, I thought it was necessary to get my head around the Wellington-based SilverStripe Content Management System.

Coming from Joomla!, I expected a module-driven, highly customisable CMS but was instead greeted with a simple interface that had clearly been designed for the end user/client.

With further investigation I began to appreciate the power of the ‘Stripe and it’s code-monkey orientation. Once you get your head around Object Oriented Programming, you can do almost anything. It’s just that initial learning curve that is the killer.

So far, in business, it looks like a very promising CMS to present our client’s websites with. It provides a very logical author backend so the client doesn’t have to be re-trained to learn how to write his own site.

But, be warned, the official documentation is outdated and updates are sparse – an effort from the developers to promote their hosting service. The business world can be a gross place.

Find out more about the SilverStripe CMS at http://www.silverstripe.org

SilverStripe 2.4.7

27 September 2012

Now that the brand-new SilverStrip 3.0.1 has been launched, most of us are keen to get our clients on the bandwagon and start developing with the flash new tools. However, if you have a more conservative client and want to stick with a highly stable release (2.4.7), then getting your hands on it can be rather difficult. So if you really don’t want to go 3.0.1 just yet, I have just the link for you.

Download SilverStripe 2.4.7

Expandable CMS Widgets

27 September 2012

Hide and show large widgets with this handy add-on.

Add to /themes/YOURTHEME/css/cms.css

     
    /* — WIDGETS HIDE/SHOW — */
    
    .usedWidgets .Widget {
     position: relative;}
    
    .usedWidgets .Widget .expand {
     position: absolute;
     top: 4px;
     right: 20px;
     color: #FFFFFF;
     font-weight: bold;
     cursor: hand;
     cursor: pointer;}
    
    
    .usedWidgets .Widget.collapsed .widgetDescription,
    .usedWidgets .Widget.collapsed .widgetFields,
    .usedWidgets .Widget.collapsed .deleteWidget {
     display: none;}

Add to /themes/YOURTHEME/js/cms.js

     $('.usedWidgets .Widget .expand').live( 'click', function(){
    
      $(this).closest('.Widget').toggleClass('collapsed');
    
     });

Download source files

If you are struggling to find out why your page’s static $db fields aren’t working, it may be due to the field name or function names.

You cannot use PageIntro as a $db field, nor can use you use GetPageIntro in your controller (ie Page.php) as a function to return content to your templates. These are protected functions. Hopefully this helps someone else out.

Debugging a SilverStripe website? Lose the impossible-to-debug ‘White Screen of Death’ with these codes:

_config.php

    error_reporting(E_ALL);

.htaccess

    php_value display_errors On

Sometimes it is just not worthwhile creating a new page type just for one tiny piece of functionality. Or perhaps you want the in-page functionality protected from accidental client tanpering? Either way, you can run functionality quite easily from within the page content with this crafty search and replace.

Page.php (inside the controller, ie Page_Controller class)

/* === MAMBOT TO ALLOW FUNCTION RUNNING FROM WITHIN ARTICLES === */
    
    function Content() {        
    
        // get current content
        $newContent = $this->Content;
        
        // if our pre-definined flag is in the content
        if( substr_count($newContent, '$TextInsideContent') > 0 ){
            // replace the flag with the content of our function
            $newContent = str_replace('$TextInsideContent', $this->CustomFunction(), $newContent);
        };
        
        return $newContent;        
    }

Reset Admin Password

2 October 2012

Locked yourself out of SilverStripe? Naturally, as the legitimate administrator you will have FTP access, so simply add this line to your /mysite/_config.php file to reset your 'admin' user password to 'password'.

/mysite/_config.php

Security::setDefaultAdmin('admin','password');

Sometimes you need to execute a function within a page article, and the easiest way is to write your functionality in your Controller (ie Page.php, Page_Controller class) and drop in a unique string within the article. In the demo below I have created a unique string '$DemoFunction' to write in my article content, which will be replaced by the content of the function DemoFunction();

In the Page_Controller class (mysite/code/Page.php)

function Content() {
// get current content
$newContent = $this->Content;

// do replacements
if( substr_count($newContent, '$DemoFunction') > 0 )
   $newContent = str_replace('$DemoFunction', $this->DemoFunction(), $newContent); 

return $newContent;
}

Instead of scrambling around the /assets folder trying to find the folder that contains your assets, set the default folder to start the search from with one sneaky line in your class:

 // create field
$thumbnailField = new UploadField( 'Picture', 'My Picture' );

// set /assets/MyPictures as default folder
$thumbnailField->setFolderName('MyPictures');

// add field to $fields object
$fields->addFieldToTab("Root.Main", $thumbnailField );

When you're frequently building SilverStripe websites, you manage to create small efficiencies to make life a bit easier. To construct a SilverStripe website quickly, I have written a quick bash script that compiles the basic SilverStripe repositories into a install-ready git repository.

Read more

1 2

Let's work together