23487 Posts in 18996 Topics by 2878 members
General questions about getting started with SilverStripe that don't fit in any of the categories above.
|Go to End||Next >|
26 July 2012 at 6:28pm
Use only $Width
27 July 2012 at 12:22am
like @Craftnet said, you don't need $Image since the loop tag places you in the image scope.
27 July 2012 at 2:37am Last edited: 27 July 2012 2:56am
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?
27 July 2012 at 5:03am
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
27 July 2012 at 5:43am
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.
27 July 2012 at 9:01am
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...
27 July 2012 at 12:50pm
Yup this looks like it does the job.
I'll be sure to note that less/greater than operators don't work in templates.
27 July 2012 at 1:10pm
Actually upon further inspection this always returns false.
I'll play around with it and let you know what I find.
|Go to Top||Next >|