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   1704 Views

Avatar
kfloks

7 November 2009 at 11:38am Community Member, 4 Posts

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

7 November 2009 at 11:33pm Community Member, 323 Posts

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

8 November 2009 at 12:20am Community Member, 4 Posts

$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

8 November 2009 at 1:27am Community Member, 243 Posts

One '=' in you comparison statement!

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

Avatar
kfloks

8 November 2009 at 2:13am Community Member, 4 Posts

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

8 November 2009 at 10:08am Community Member, 901 Posts

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

8 November 2009 at 11:53pm Community Member, 4 Posts

Thank you, banal! It works!

This is full working code:

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