Snippets - Little bits of code to make you happy
-
SnippetsSet the Redirect after a successful Member Login
31 May 2010 | | | Supports v2.4, v2.3
TweetThe Member system that comes with SilverStripe offers substantial control over your site's authentication capabilities. It often requires the developer to build out or extend most common functionality to websites. This is great in that you are never "stuck" with the out-of-the-box offerings, but as any SS dev knows you end up with a little bag of Member tricks that gets used across many projects. Presented here is one that I use often.
Continue reading... -
SnippetsAutomatically ?flush when in 'dev' mode
15 April 2010 | | | Supports v2.4, v2.3
TweetOften when doing development work on a website - and particularly the templates - it can be a pain having to remember to add ?flush to the end of the URL to make sure all of your changes have come through. I'm sure that all of us have had that "d'oh" moment when we have spent too much time wondering why our changes weren't working, only to find a simple flush fixed it.
Continue reading... -
SnippetsPreventing malicious SQL injections
12 March 2010 | | | Supports v2.4, v2.3
Tweet
PHP has a very shallow learning curve, it's free and anyone can have a go at making a website by following a few tutorials and implementing their experience with other languages. However, coding for the web can be a risky business, especially with dynamic websites that take some kind of user (or external) input and use that to get data from a database.
Continue reading... -
SnippetsDisable Default JavaScript Behaviours
15 February 2010 | | | Supports v2.4, v2.3
TweetBy 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:
Continue reading... -
SnippetsSelect a theme using a URL parameter
21 December 2009 | |
TweetWhen 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... -
SnippetsUsing a Print Stylesheet
16 December 2009 | |
TweetOften 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:
Continue reading... -
SnippetsUsing Dates in Foreign Languages
17 November 2009 | | | Supports v2.4, v2.3
TweetWith 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... -
SnippetsOverriding Silverstripes language files with your own
28 October 2009 | |
TweetIn 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... -
SnippetsExtending $LinkingMode to handle controller actions
20 October 2009 | |
TweetAs 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... -
SnippetsHide pages in Sitetree that a user can't edit
15 September 2009 | | | Supports v2.4, v2.3
Tweet 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... -
SnippetsSpice up Your CMS Sitetree
27 August 2009 | | | Supports v2.4, v2.3
Tweet
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...
-
SnippetsHow to access your admin account when you've forgotten the password
22 August 2009 | |
Tweet I managed to forget my admin password and found quite a few ways to unlock an SS install. I originally thought about poking around the database and changing the hashes myself. After reviewing the Security and password encryption code, I would recommend against doing that. SilverStripe uses salted SHA1 encryption which is no fun to try and create yourself. Also you'd have to update multiple tables to get the password changed. Luckily the SS Core team has included multiple features for accomplishing this. The options below assume you have access to your webserver to use some PHP code. Continue reading... -
SnippetsClearing the Search field on click with jQuery
5 August 2009 | |
TweetAs with everything, it's attention to detail that makes great sites. One thing that really bugs me is when a site has a search box with the word 'search' inside it but which does not clear it self when clicked, meaning I have to clear it before I can search. Given it can be achieved with a few lines of jQuery, it's a real surprise how many sites fail to implement this, or that still use the 'onclick' inline javascript event.
Continue reading... -
SnippetsManipulating every Nth item in a <% control %> loop
16 July 2009 | | | Supports v2.4, v2.3
TweetOften 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... -
SnippetsRemoving an Item From the Main CMS Menu
3 July 2009 | |
TweetIf you want to remove an item from the CMSTopMenu without making it inaccessible you can add this line to your _config.php file:
CMSMenu::remove_menu_item('SecurityAdmin');Continue reading...