Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

Template Questions /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Best Practices for Links???

Go to End

2 Posts   1653 Views


Community Member, 6 Posts

10 September 2009 at 5:00am

I have created a template for my home page that has 3 images that will link to different parts of the web site and to other sites. I would like to know the best practices for creating the links for the images. They need to be modified by the content editor, so they cannot be hardcoded. I currently have a text field where the editor can just paste the link, but it seems like I should be able to create a field type that would allow me to pick the link or link to an external site, just like the CMS allows you to configure a link. I considered creating links like a sub page and using some api to select a particular link value from the children collection. I am not crazy about that approach because it is not clear to the user and is separated from the content. What is the best practice for this situation?

Thanks in advance for your help.


Community Member, 541 Posts

10 September 2009 at 7:25am

You can create a has one link to site tree, so in your page class:


public static $has_one = array(
	'Link1Loc'	=> 'SiteTree',

function getCMSFields() {
	$fields = parent::getCMSFields();


	$fields->addFieldToTab( 'Root.Content.Intro', new TreeDropdownField( 'Link1LocID', 'Link 1 Location', 'SiteTree' ) );	

	return $fields;


Then in your template you just need to use $Link1Loc.Link

Hope that helps,