Snippets - Little bits of code to make you happy
21 May 2009 | | | Supports v2.4, v2.3Tweet
This snippet lets you add a thumbnail to items in UncleCheese's Data Object Manager module or a regular Complex Table field. All you need to do is create a function that returns a thumbnail and refer to this function in your DOM or CTF definition.Continue reading...
12 June 2010 | |Tweet
By Default, SilverStripe uses the <input type="submit"> tag for it's form actions. However, sometimes you may want to use the <button> tag to give you a little more control over styling. This snippet shows you how, as well as giving you code to achieve the same thing in UserForms!Continue reading...
SnippetsUsing a Password Validator
18 October 2010 | |Tweet
The Password Validator allows you to set particular criteria for your members passwords. For example if you wanted to have a minimum length of 8 characters and contain lowercase and uppercase characters, well that's a simple case of adding a couple of lines to your _config.php file!Continue reading...
SnippetsSpice up Your CMS Sitetree
27 August 2009 | | | Supports v2.4, v2.3Tweet So you have created your own page types, but they all look the same in your CMS site tree. Time to make them more recognizable! This is quite easy, but it can make your site tree a lot more attractive. Continue reading...
SnippetsUsing Dates in Foreign Languages
17 November 2009 | | | Supports v2.4, v2.3Tweet
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.Continue reading...
SnippetsCreating a Page Export Function
6 May 2009 | | | Supports v2.4, v2.3Tweet
Need to create an 'export' function for a page? Do it quickly and cleanly with HTTP::sendFileToBrowser. In your page controller, add a new action 'export':Continue reading...
20 October 2009 | |Tweet
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.Continue reading...
9 June 2011 | | | Supports v2.4, v2.3Tweet
Although Silverstripe has a mechanism for alternative configuration per environment, using the ConfigureFromEnv() method in your mysite/_config.php file, it has its limitations and I have often read people complaining about it. Here is a simple yet powerful alternative to using SilverStripe environment files.Continue reading...
28 October 2009 | |Tweet
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.Continue reading...
16 July 2009 | | | Supports v2.4, v2.3Tweet
Often you will want to manipulate every nth item inside a <% control %> loop. For example say you had a gallery and you wanted every 3rd image to start on a new line, you need to be able to test each item from the template to see if it is divisible by 3 and should therefore have the clear CSS class added to it.Continue reading...
SnippetsGet errors e-mailed to you
24 March 2009 | | | Supports v2.4Tweet
If your site is live it means you are probably not getting errors reported in the view, so it's handy to have them emailed to you so you can still debug and also be notified if something is up.
Add this line to your mysite/_config.php file and expect some mail!
SS_Log::add_writer(new SS_LogEmailWriter('firstname.lastname@example.org'), SS_Log::ERR);
15 February 2010 | | | Supports v2.4, v2.3Tweet
21 December 2009 | |Tweet
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.Continue reading...
15 September 2009 | | | Supports v2.4, v2.3Tweet Sometimes you want to hide pages in the Sitetree that members logged into the CMS don't have permission to edit. This is really simple in because they already have a css style applied to them you can just hide that class. You need to include this snippet in your typography.css file so that it is included in the CMS. Continue reading...
23 June 2009 | | | Supports v2.4, v2.3Tweet
Often you will want to control which users can create, edit, delete and publish certain page types. For example you may only want high level users to be able to create ContactPage page types, or prevent low level users from deleting HomePage page types. This can easily be achieved by adding these functions to the page type model (usually just before getCMSFields()). Then within the function you can define conditionals which decide whether to return true or false.Continue reading...