Snippets » CMS menus
15
Sep
3
Hide pages in Sitetree that a user can't edit
Submitted by Howard Grigg
Very short snippet here - 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.
Read More >>27
Aug
6
Spice up your CMS Sitetree!
Submitted by Martijn van Nieuwenhoven
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.
First grab some icons, buy them or create you own custom aesthetic icon set. They only thing you have to keep in mind, is that your icons need to be saved as youriconname-file.gif.
Next create a folder in mysite, like /images/icons, to store your icons.
To assign a icon to your page class, add the a static $icon var to your page class like:
Read More >>
28
Jul
13
Autofill MetaDescription and MetaKeywords on page save
Submitted by Martijn van Nieuwenhoven
Most of my customers don't want to add meta info manually, so I add an onBeforeWrite function to update the Meta Description field and count the keyword density of the content with a separate function and add these keywords to the Meta Keywords fields when a page is saved.
In my humble SEO opinion every page needs an unique Meta Description. Keywords seems to be less important for search engines, but why not add them automatically anyway! The function counts how many times each word exist in the Content, order the words by occurrence and glues the words to a comma separated string. In this function only words with more then 4 characters are counted, but you can adjust that if you like.
Read More >>24
Jul
34
Customising the WYSYWIG editor in v2.3.2 (TinyMCE)
The default install of SilverStripe contains an array of buttons for the TinyMCE HTML editor. However usually your client will need some extra functionality or you may want to keep things simple for them by removing some of the buttons. As of SilverStripe 2.3.2 this is very easy and can be achieved by adding some code to the _config.php file.
Note. if you are using a version <2.3.2 you must edit the file cms/javascript/tinymce.template.js.
To find out all the wonderful buttons that are available by default in the TinyMCE 3 install visit the example page here and click the 'view source tab'. There are also tons of plugins available to do all sorts of things.
Adding Buttons
So
lets say for example you wanted to add font color settings to the
editor. All you need to do is add this line to your class or
_config.php file:
03
Jul
1
Removing an Item From the Main CMS Menu
If you want to remove an item from the CMSTopMenu without making it inaccessible you can add this line to your _config.php:
This example will remove the Security link.
Note. You would still be able to access the Securtiy section by going to admin/security, it just won't show in the menu.
Read More >>
10
Jun
1
Change the CMS "Help" Link
Usually you can change the CMS menu settings from your site configuration, but the "Help" link is hard-coded to allow for translations. This snippet, placed in your site configuration file will override the "Help" link with a link back to your site:
Read More >>21
May
11
Adding a Thumbnail to a DataObjectManager or Complex Table Field
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.
So add a function like this to your DataObject class:
30
Apr
15
Dynamically Generating a Dropdown List
If you want to create a drop down list (or option set) dynamically, for
example from a set of pages or DataObjects, you can use the DataObject::get() call along with the function toDropdownMap() to generate it like so:
26
Apr
0
Create a Field in 'Page' but not it's Decendents
This snippet allow you to add a field only to a page of type 'Page' and not those pages which extend Page.