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.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

getting more control (or less?) over images


Go to End


6 Posts   908 Views

Avatar
lozhowlett

Community Member, 151 Posts

6 October 2011 at 1:23am

Guys

I want to output an image with an onmouseover effect (changing a large image for the one selected onmouseover from a list of thumbs).

<% control Resources %>
<% control Attachment %>
$CroppedImage(81,80)
<% end_control %> 
<% end_control %>

how do I get into do something like...

<% control Resources %>
<% control Attachment %>
<img src ="$attachment.url" onmousemove="somejavaScriptfnc()">
<% end_control %> 
<% end_control %>

as this just produces img src = "".

Thanks!

Avatar
MarcusDalgren

Community Member, 288 Posts

6 October 2011 at 1:40am

If you're in the Attachment loop then skip the prefix.
It should just be

<img src="$URL" onmousemove="somejavaScriptfnc()"> 

Avatar
Phill

Community Member, 81 Posts

6 October 2011 at 1:41am

I think you want to do something like this

<% control Resources %>
<% control Attachment %>
<img src ="<% control SetRatioSize(81,80) %>$URL<% end_control %>" onmousemove="somejavaScriptfnc()">
<% end_control %>
<% end_control %>

Avatar
lozhowlett

Community Member, 151 Posts

6 October 2011 at 2:08am

cool - thanks guys, both works, just personal preference how I end up doing it in the template. cheers!

Avatar
Ryan M.

Community Member, 309 Posts

6 October 2011 at 7:55am

PROTIP: You can save yourself some lines of code by shortening the block to:

<% control Resources %>
<img src ="<% control Attachment.SetRatioSize(81,80) %>$URL<% end_control %>" onmousemove="somejavaScriptfnc()">
<% end_control %>

Avatar
swaiba

Forum Moderator, 1899 Posts

6 October 2011 at 10:31pm

I wouldn't over use the dot notation because the template will fail if not present, the control tag would not.
Also the dot notation cannot be chained nore than once (i think, so something.this is ok, but some.thing.else isn't ok).