Snippets - Little bits of code to make you happy
-
SnippetsSilverStripe developer bookmarklets
2 April 2012 | | | Supports v2.4, v2.3
Tweet
Here are some handy dynamic bookmarklets for your browser for one click access to things like rebuilding the database, flushing the cache and accessing the CMS!
Continue reading... -
SnippetsAutomatically Redirect to the first Child Page without a Redirector Page
27 September 2011 | | | Supports v2.4
TweetThis is a little snipped i've been using to redirect a custom page to it's first child. It extends the init method of the Controller. This has proven useful in cases where the client wants to re-sort the child pages and doesn't want to mess around the configuration of a redirector page.
Continue reading... -
SnippetsInserting Javascript into a DOM Popup
11 September 2011 | | | Supports v2.4, v2.3
TweetI recently ran into the problem of how to insert my own Javascript into a DOM (DataObjectManager) popup window. After much googling and getting nowhere I resorted to reading the code and discovered that it was in fact quite simple to do.
The problem I was trying to solve was for a dropdown select box to toggle fields in the form, depending on whether a link is internal or external to the site.
Continue reading... -
SnippetsHighlighting Query Text in Search Results
12 July 2011 | | | Supports v2.4
Tweet
Most search results I have seen with Silverstripe just return the Summary of the page or the FirstSentence. I have knocked up a quick way to show a sentence from the page that contains the search term and even highlights it for you.
Continue reading... -
SnippetsAn alternative to _ss_environment Files for easy 'Per Environment' Configuration
9 June 2011 | | | Supports v2.4, v2.3
TweetAlthough 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... -
SnippetsMaking the Tree Tools sticky for easier editing on large sites
22 March 2011 | | | Supports v2.4
Tweet
If you have ever had to edit content on a SilverStripe site with lots of pages, you will have noticed how furstrating it is to have to keep scrolling back up the tree panel to create a page or enable drag and drop re-ordering. Well, here is a handy bit of CSS you can add to keep the tools static, even as you scroll down the tree.
Continue reading... -
SnippetsDynamically Combining CSS and Javascript Files for Faster Loading using Requirements
4 December 2010 | | | Supports v2.4, v2.3
TweetAs you will most likely already know, reducing the number of HTTP requests that your site makes can have a significant effect on loading times. However, usually it's not practical to combine all your files into a single one for reasons of maintainability. This is where SilverStripe steps in and provides an elegant, automated solution to this common 'requirement' (lol, get it?).
Continue reading... -
SnippetsOptimizing Complex Models
4 November 2010 | | | Supports v2.4, v2.3
TweetThe SilverStripe ORM engine (Sapphire) makes working with your database a breeze, but that simplicity comes at a cost. Each database query contributes to slower page load times and a complicated data structure can create significant performance issues.
Here are a number of strategies that can be employed to improve your website query performance:
Continue reading... -
SnippetsUsing a Password Validator
18 October 2010 | |
TweetThe 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... -
SnippetsRemove theme selector from SiteConfig
15 October 2010 | | | Supports v2.4
Tweet2.4 has introduced the SiteConfig, which by default allows the user to switch themes - if they exist.
It's incredibly useful to have this functionality built-in now, but for those that only have one theme for a site, it's a bit of unnecessary clutter. Here is how to remove it by using a decorator
Continue reading... -
SnippetsAdding Gravatars to your site
8 October 2010 | | | Supports v2.4, v2.3
Tweet
Gravatar is a great service that allows you to pull in members profile photos directly from their Gravatar accounts. It's used right here on SSbits and it also part of the Forum module. It's also incredibly easy to integrate into your site!
Continue reading... -
SnippetsGetting items from a has_many or many_many relation
7 October 2010 | | | Supports v2.4, v2.3
TweetHave you ever found yourself using DataObject::get() to fetch objects in a has_many so that you can filter/sort them easily?
Well as it happens there is no need to do this thanks to a totally undocumented bit of code!
Continue reading... -
SnippetsA Data Object Manager Cheatsheet
6 October 2010 | |
TweetWe all love the DataObject Manager (DOM, not to be confused with the Document Object Model) as well as its creator UncleCheese of LeftAndMain.com. However one thing which has always frustrated me is having to look back through my code or even worse having to search the forums to find that function to set the upload folder, or create a filter for my DOM. So here within this page, lies a comprehensive list of all the things you can do with your DOM and File/ImageDOM. Viva la DOM!
Continue reading... -
SnippetsA _config.php Cheatsheet
2 July 2010 | | | Supports v2.4
Tweet
If your anything like me, you've probably found yourself going through your previous sites looking for that line of code to put in your _config.php file. Well, now you nolonger need to, simply bookmark this page and return to it any time you need to add a line to your config! And if I've missed out anything leave a comment and I'll make sure it gets added :)
Continue reading... -
SnippetsCustomise Form Actions to use the <button> tag
12 June 2010 | |
TweetBy 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...