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're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

Template Questions /

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

How to get image orientation in template?


Go to End


7 Posts   2324 Views

Avatar
kfloks

Community Member, 4 Posts

7 November 2009 at 11:38am

I need somethig like this:

<% if Photo.Orientation == 1 %>
         $Photo.$SetHeight(200)
<% else_if %>
         $Photo.$SetWidth(200)
<% end_if %>

Dont work!

Can anybody help me?

Avatar
Juanitou

Community Member, 323 Posts

7 November 2009 at 11:33pm

Hi!

I don’t know where this Orientation propriety is coming from (I guess you added it to the Photo class) but your code will never work if you don’t remove the $ before SetHeight and SetWidth.

Hope it helps,
Juan

Avatar
kfloks

Community Member, 4 Posts

8 November 2009 at 12:20am

$Image.Orientation - It's a SilverStripe property ( http://doc.silverstripe.org/doku.php?id=image ).
It returns 1 if image vertical, and 2 - if horizontal. And I can't work with this values in my template, like this

<% if Photo.Orientation == 1 %> 
     $Photo.SetHeight(200) 
<% else_if %> 
     $Photo.SetWidth(200) 
<% end_if %>

and Photo:

   static $has_one = array(
      'Photo' => 'Image'
   );

Avatar
dhensby

Community Member, 253 Posts

8 November 2009 at 1:27am

One '=' in you comparison statement!

<% if Photo.Orientaion = 1 %>
....
<% else %>
....
<% end_if %>

Avatar
kfloks

Community Member, 4 Posts

8 November 2009 at 2:13am

Still don't work!

And in SS templates for comparision use ==
(http://doc.silverstripe.org/doku.php?id=templates&s=property)

Avatar
bummzack

Community Member, 904 Posts

8 November 2009 at 10:08am

Nope. It's = in templates (not ==).
Maybe try the following:

<% control Photo %>
<% if Orientation = 1 %>
$SetHeight(200)
<% else_if %>
$SetWidth(200)
<% end_if %> 
<% end_control %>

Avatar
kfloks

Community Member, 4 Posts

8 November 2009 at 11:53pm

Thank you, banal! It works!

This is full working code:

  <% control Photo %> 
     <% if Orientation = 1 %> 
       $SetHeight(200) 
     <% else %> 
       $SetWidth(200) 
     <% end_if %> 
   <% end_control %>