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've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Archive /

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

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

Linking an ImageField to a page


Go to End


4 Posts   2263 Views

Avatar
streetdaddy

32 Posts

21 September 2007 at 4:22am

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

Avatar
streetdaddy

32 Posts

21 September 2007 at 4:23am

and the screenshot...

Avatar
streetdaddy

32 Posts

21 September 2007 at 3:19pm

Edited: 21/09/2007 3:19pm

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

Avatar
Matt

Community Member, 86 Posts

23 September 2007 at 10:06pm

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.