Jump to:

3443 Posts in 1030 Topics by 871 members

Template Questions

SilverStripe Forums » Template Questions » Best Practices for Links???

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

Page: 1
Go to End
Author Topic: 1252 Views
  • KeithLeslie
    Community Member
    6 Posts

    Best Practices for Links??? Link to this post

    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.

  • Mo
    Community Member
    508 Posts

    Re: Best Practices for Links??? Link to this post

    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,


Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.