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.

Template Questions /

How to get image orientation in template?


Reply


7 Posts   1735 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 ( [url]http://doc.silverstripe.org/doku.php?id=image[/url] ).
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
Pigeon

Community Member, 243 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 ==
([url]http://doc.silverstripe.org/doku.php?id=templates&s=property[/url])

Avatar
banal

Community Member, 901 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 %>