Welcome to SSbits! Here you will find tutorials, code snippets and other web related goodies all geared towards the fantastic SilverStripe CMS. Our aim is to help people get up to speed with the great features of SilverStripe even quicker than we did and hopefully provide some inspiration along the way!
25
Nov
1
Snippet: Extend Meta description beyond 255 character limit
Submitted by Marijn Kampf
Search engines prefer to display a description in their result pages that include the keywords searched for, to ensure they pick and mix sentences from your meta description rather than random bits from your page it can be helpful to have a longer meta description. This allows for more room to include your keywords.
Changing the field length couldn't be simpler, in the file mysite/code/Page.php add the MetaDescription type as Text.
13
Nov
14
Tutorial: Using jQuery for form validation
As you may have noticed, SilverStripes built in form validation is based on Prototype and is pretty limited. It also means that even though you might be using jQuery for other things on your site, you will still need to load prototype.js and all the accociated files that SilverStripe requires for it's built in JavaScript form validation.
However, using a jQuery validator, such as the excellent Validate plugin has some obvious benefits:
- Validate multiple forms on a single page
- Customize error messages
- More control over inline error styling
- Remove the need for loading extra JS files, such as Prototype.js and Behavior.js etc. (more than 90KB in total)
- Extended validation options as well as the ability to create custom regex validation rules.
So now that you are (most likely) convinced about the benefits of using jQuery validation let's get started.
Read More >>11
Nov
0
Snippet: Add Syntax Highlighting to the SS Forums
Submitted by Dalesaurus
Get Firefox, install Greasemonkey, Then install the following userscript:
http://www.silverstripe.org/assets/Uploads/silverstripeforumscode0.1.user.js

Updates and more here: http://www.silverstripe.org/general-questions/show/272688
Read More >>07
Nov
5
Snippet: Using dates in foreign Languages
Submitted by Francisco Arenas
With all the translatable, i18n and other translation related stuff in silverstripe, I think more than one is wondering how to achieve something simple as using dates in a foreign language... Actually, it's ultra easy if you add this 2 lines in your silverstripe powered website: (my spanish example)
in _config.php:
in your template:
this will render:
miércoles 21 de octubre de 2009
02
Nov
12
Tutorial: Web 2.0 Mirrored Images
Submitted by Dieter Orens
Ever wanted to create the so-called 'web 2.0' mirrored images as you can see on http://www.dio5.com/portfolio/, without having to manually rotate and proces the image? Then this one is for you.
I attached a fully working zip-package, but let's run through some of the code nonetheless.
When it comes to images the Image and GD class are the ones we need to tackle. Create a file in your mysite/code/ folder called ImageDecorator.php and add in the next code:
Read More >>28
Oct
7
Snippet: Overriding Silverstripes language files with your own
Submitted by Marcus Dalgren
In my most recent project I've had to run a site in another language (Swedish) and run into some issues which I thought I'd share with all of you.
Now Silverstripe probably comes with a translation for your language but even if it does, you probably want to change the wording of some of the phrases, so what to do?
You could of course hit up the language files for the relevant module or the ones in cms and sapphire but you really don't want to touch these files if you can help it.
Read More >>21
Oct
0
Blog: SilverStripe London Feature Talk, Nov 4th
O
n Nov 4th GPMD will be hosting the first Feature meetup which will include a talk demontration realting to an aspect of SilverStripe.
From the page on meetup.com:
"The format for the UK SilverStripe meetup has changed slightly. From now on we will host a feature meetup every 3 months (this will have a talk / demonstration etc..) each subsequent meetup will remain as an informal gathering of users wishing to have a few drinks.
The November meetup will include a talk from Jamie Neil, Technical Director of GPMD Ltd. Jamie is going to demonstrate the Nesta Creative Credits project and explain a little about how GPMD approached the development.
Take a look at the site and bring along your questions for Jamie. http://www.creative-c..."
So if any of your are fellow Londoners I look forward to seeing you there!
20
Oct
1
Snippet: Extending $LinkingMode to handle controller actions
Submitted by Marcus Dalgren
As some of you might have noticed, as soon as you step outside of the standard SiteTree structure you're pretty much on your own. Today I had to make a menu that mixed normal SiteTree pages and controller actions.
I wanted to be able to use LinkingMode to check if this is the currently viewed page and unfortunately the standard function does not take controller actions into account.
The Snippet
Read More >>
06
Oct
13
Tutorial: Detecting Mobile Browsers to Re-Theme Your Site
Submitted by Richard Rudy
With the proliferation of Smart Phones and other non-traditional-computer ways to browse the internet, wouldn’t it be great if you could provide a custom browsing experience for different users?
You could re-template your site using the sub-sites module, but it might not be stable/functional enough for every one yet. So I’ll show you how to use Anthony Hand’s great User Agent Detection Class to re-template your site based on the User Agent of your visitor.
First things first get yourself a copy of the Class from the link above. He also has a lot of great resources on designing for mobile browsers.
Read More >>21
Sep
3
Snippet: Making a hierarchy aware templating system
Submitted by Marcus Dalgren
Something that has been bothering me when building larger sites with SilverStripe is that I often find myself creating new classes not to add functionality, but to just get a new template.
You can set separate templates for different actions manually but that's not what I want in this case, I want different templates for the same action on the same class.
After thinking about this for awhile I came up with a two part solution and the first part is to make the template choosing aware of the Sitetree hierarchy.
In order to get this to work I have sub classed ContentController with a class I call HierarchyController. This class only contains two methods, namely a __construct() method to kick start the parent and a method called getViewer which overrides the getViewer method of the Controller class.
The code in getViewer consists of the code from the parent method with my own code added at the end. The reason I copy the code from the parent is that I want to do the same processing it does first and then do my own. Since the parent method returns an SSViewer object with the templates already set it's too late for me to step in and make the needed changes (I think).
The Snippet
So the added code is as follows: