Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » Linking an ImageField to a page

Our old forums are still available as a read-only archive.

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

Page: 1
Go to End
Author Topic: 1859 Views
  • streetdaddy
    Avatar
    32 Posts

    Linking an ImageField to a page Link to this post

    I have added a couple of ImageField's to one of my templates to get complete control of the HTML output.

    But also I want to link the Image to another page in the site. Is there a field or some method that allows the user to select a page from a list? ie. the same as you can using the link dialog used by HtmlEditorField editor.
    I've attached a screenshot that might make more sense of what I need to do.

    Unfortunately the editor adds unwanted <p> and/or <br> with the image, and I need to have no margin/padding etc. around it.

    Thanks in advance for any advice...

  • streetdaddy
    Avatar
    32 Posts

    Re: Linking an ImageField to a page Link to this post

    and the screenshot...

  • Andy
    Avatar
    230 Posts

    Re: Linking an ImageField to a page Link to this post

    TreeDropdownField is probably what you're looking for.

  • streetdaddy
    Avatar
    32 Posts

    Re: Linking an ImageField to a page Link to this post

    Perfect, thanks

    Just in case it helps anyone, this is what I ended up with:

    $fields->addFieldToTab('Root.Content.Main', new TreeDropdownField('MainImageLink', 'Link image to', 'SiteTree'), 'Content');

    see http://doc.silverstripe.com/doku.php?id=treedropdownfield&rev=1164666507

  • Matt
    Avatar
    Core Development Team
    84 Posts

    Re: Linking an ImageField to a page Link to this post

    FYI, that should be new TreeDropdownField('MainImageLinkID', ...)

    Because when you have a $has_one relationship, the database field gets created as MainImageLinkID, and currently TreeDropdownField will just save the object's ID to whatever name you give it, it won't try to figure out what relationship you're actually using it on.

    1859 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.