In this section you will find short snippets of code that we have found useful and often hard to uncover.
17
Feb
1
Database Configuration Management
Submitted by Hamish Campbell
Wouldn't it be easy to have a single environment configuration for all your SilverStripe sites without having to reconfigure each one individually? Wouldn't it be great not to have to change environment settings when you push your site from development to live servers? This is easy to achieve using the SilverStripe "ConfigureFromEnv" script.
To set this up, remove your $databaseConfig line from your site _config.php and add:
mysite/_config.php
Then create a new _ss_environment.php file. This can live in your web root, in it's parent or it's parent parent folder. Define the following constants:
Read More >>15
Feb
0
Disable Default JavaScript Behaviours
Submitted by Hamish Campbell
By default SilverStripe uses bulky and sometimes unwanted JavaScript libraries to handle form validation and AJAX page commenting features. Often you want to disable this behaviour so you can integrate your own JavaScript code. This is easily achieved with the following two lines in you site configuration file:
mysite/_config.php
Read More >>
05
Jan
0
Add attachments to Silverstripe Form submissions
Submitted by Francisco Arenas
Today I was trying to add a CV file to a silverstripe form for a project and noticed that is not that easy as it sounds. Well with the help of Martijn we figured it out:
First the form
21
Dec
1
Select a theme using a URL parameter
Submitted by Toby Champion
When I develop SilverStripe sites, I usually get functionality working in the default theme blackcandy before getting it working in the final templates. This way, authors can start adding content and seeing how it looks on the page, and I can get early feedback about the functionality. Also, as a developer I get to see real content in the browser early in the process. So does the designer.
I'm sure this process is nothing new - and I realise form-first vs function-first is an old debate - but one thing I wanted to share is some code my team and the client found useful in a recent project.
I added the ability to select a theme based on a parameter in the URL, either for the current page request or for session. This meant we were able to throw around URLs specifying the theme, choosing a theme depending on whether we were discussing the (visual) design or the functionality and content.
Read More >>16
Dec
3
Using a Print Stylesheet
Often people want to be able to print webpages without all the menus and graphics and with all the content fitting correctly onto a page. To do this you need to create a separate print stylesheet. It would look something like this:
themes/YOURTHEME/css/print.css
Read More >>25
Nov
1
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.
11
Nov
0
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
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
28
Oct
3
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 >>20
Oct
0
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.