Jump to:

5513 Posts in 1732 Topics by 1218 members

Customising the CMS

SilverStripe Forums » Customising the CMS » $image as link

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

Page: 1
Go to End
Author Topic: 772 Views
  • roblet
    Avatar
    Community Member
    5 Posts

    $image as link Link to this post

    I would like to do the following with the CMS so that I can pick am images from the files area and then also select a link of a page for it to go to.

    <% if Image%>
    <p><a href="$ImageLink">$Image.SetWidth(222)</a></p>
    <% end_if %>

    I have figured out the Image part but what I need to do is to setup a drop down in the backend to select a page from the CMS

    If anyone is able to help that would be good.

    Thank you

  • simon_w
    Avatar
    Forum Moderator
    471 Posts

    Re: $image as link Link to this post

    What you're after is a TreeDropdownField. http://doc.silverstripe.org/treedropdownfield has an example about using it to select a Page.

  • roblet
    Avatar
    Community Member
    5 Posts

    Re: $image as link Link to this post

    Hi,

    Thank you for the link. I have tried a few different options to get this working and cannot figure this out. I am not really a developer so there is a little more guess to this. This is what I have now the problem is I cannot figure out how to make this appear in the backend so i can select a page:

    static $has_one = array(
    'Banner' => 'Image',
    'Podone' => 'Image',
    'Podtwo' => 'Image',
    'Podthree' => 'Image',
    'RightContent' => 'SiteTree'

    );

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

    $fields->addFieldToTab("Root.Content.Banner", new ImageField('Banner'));
    $fields->addFieldToTab("Root.Content.Pods", new ImageField('Podone'));
    $fields->addFieldToTab("Root.Content.Pods", new ImageField('Podtwo'));
    $fields->addFieldToTab("Root.Content.Pods", new ImageField('Podthree'));
       $treedropdownfield = new TreeDropdownField("RightContentID", "Choose a page to show on the right:", "SiteTree");

    return $fields;

    I tired a few different things but nothing worked.

    Thank you in advance

    Rob

  • roblet
    Avatar
    Community Member
    5 Posts

    Re: $image as link Link to this post

    I ended up using this

    $fields->addFieldToTab("Root.Content.Pods", new TreeDropdownField('PodlinkoneID', 'Select the page...', 'SiteTree'));

    I got a few errors but this was because I needed to add .URLSegment in the page.ss

    $Podlinkthree.URLSegment

    772 Views
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.