@Liam
Use only $Width
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.
- Previous 10 entries
- 1
- 2
- Page 33(current)
- 4
- 5
- Next 10 entries
like @Craftnet said, you don't need $Image since the loop tag places you in the image scope.
Oh. Duh.
One last thing.
Is there no way to compare less than in the template logic?
Or is there an image function I can use in the template that only resizes the image if it's larger than a certain width?
In the template, if I have an image over 800px I want to resize it to 800px, SetWidth(800), but if it's smaller, than display normal.
Or do I have to extend the image class and do it from there?
never tried greater or smaller than operator in templates, but I had in mind than SS3 template logic is now better. Did you try <% if $Image.Width < 800 %> or similar?
Otherwise you might be able to create a test function in your controller that returns a boolean, with something like this:
<% if $isBigger($Image.Width, 800) %>
you can extend the Image class but it doesn't seem necessary here
Ya I was trying <% if $Width < 800 %> while in the Images scope but it throws an error and it's the less than operator that is causing it. $Width returns proper value.
I didn't see anything in the template docs about < > so I don't think it's supported. Oh well.
try using this in the template then:
<% if $greaterThan($Width, 800) %>
<% end_if %>
with this in the controller
public function greaterThan($value, $reference)
{
if ($value > $reference) return true;
else return false;
}
there might be better solutions, but this could work...
Yup this looks like it does the job.
I'll be sure to note that less/greater than operators don't work in templates.
Cheers,
Actually upon further inspection this always returns false.
I'll play around with it and let you know what I find.
Thanks.
- Previous 10 entries
- 1
- 2
- Page 33(current)
- 4
- 5
- Next 10 entries