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.

General Questions /

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

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

[SOLVED] SS3 Upload many files/images [SOLVED] Resize image if it's larger than a certain width


Reply


35 Posts   5613 Views

Avatar
colymba

Community Member, 25 Posts

27 July 2012 at 9:50pm

works fine in my test.
check your image size and maybe add some print functions in the controller function to check.

Avatar
Liam

Community Member, 470 Posts

28 July 2012 at 2:32am

The issue is that I'm calling the function within the scope of Images that I've setup with a many_many because of the SS bug.

Avatar
Craftnet

Community Member, 58 Posts

28 July 2012 at 3:07am

Maybe use SS 3.0.1 RC2

Avatar
Liam

Community Member, 470 Posts

28 July 2012 at 5:11am

I don't think it was fixed in that RC according to the change log.

It's more of a scope issue. I don't know how to call the function within the Image loop. I've tried $Top in some places, but so far nothing.

Avatar
colymba

Community Member, 25 Posts

28 July 2012 at 10:58pm

if you are in the loop, use $Up to move one level up in the scope. Which should make something like <% if $Up.greaterThan($Width, 800) %>
all the answers are here [url]http://doc.silverstripe.org/framework/en/reference/templates[/url]

Avatar
Liam

Community Member, 470 Posts

29 July 2012 at 7:54am

I had originally tried that with $Top and no luck. Same goes for $Up.

If I use your function outside of the Images loop it returns correctly

See anything wrong with this:

public function greaterThan($value, $reference) {
      if ($value > $reference){
         return true;
      }
      else{
         return false;
      }
   }

<% loop Images %>
         <% if $Up.greaterThan($Width, 800) %>
            <a href="$SetWidth(800).URL" class="itemPhotos <% if MultipleOf(5) %> itemPhotosLast <% end_if %>" title="$Title">$CroppedImage(158,158)</a>
         <% else %>
            $Width
         <% end_if %>
      <% end_loop %>

I'm just putting $Width in the else block to see how it returns. It always returns false and I have images both smaller and larger than 800. I've tried $Up, $Top and at the front and end of the function just to test. Nothing works. Always false.

Avatar
colymba

Community Member, 25 Posts

30 July 2012 at 10:52pm

$Up seems to work fine on my setup.
can you attached your files, Model, Controller and Template?

Avatar
Liam

Community Member, 470 Posts

2 August 2012 at 8:17am

Here is the php - http://pastebin.com/g0dMJL0w

Here is the template - http://pastebin.com/nH4N6uu4