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 /

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

Conditional Image Sizes

Go to End

2 Posts   1169 Views


Community Member, 99 Posts

20 July 2010 at 12:00am

Edited: 20/07/2010 12:23am

Where can I find info on controlling image sizes.?

I have a pull down in my cms "CSSBoxStyle" and based on that pull down value i want to set the size of the image displayed.

if they choose nostyle then its 218 pixels wide
else its 294 pixels wide

i'm struggling with my if statements

Is it best to do this in the SS file or the PHP image class?

example PHP


class RightContent extends DataObject {

static $db = array(
'Title' => 'Text',
'Description' => 'HTMLText',
'ImageLink' => 'Varchar(255)',
'CSSBoxStyle' => "Enum('styleone, styletwo, stylethree, stylefour, nostyle')"

static $singular_name = 'RightContent';
static $plural_name = 'RightContents';

static $has_one = array(
'Page' => 'Page',
'SideScreenImage' => 'RightContent_SideScreenImage'

static $defaults = array(
'Title' => ''

public function getCMSFields_forPopup() {

$fields = new FieldSet(
new ImageField('SideScreenImage','MainImage (Optional)'),
new TextField('ImageLink', 'Add URL Link to Image (Optional)'),
new TextField('Title', 'Title'),
new SimpleHTMLEditorField('Description','HTML'),
new DropdownField('CSSBoxStyle', 'CSSBoxStyle', singleton('RightContent')->dbObject('CSSBoxStyle')->enumValues())



return $fields;

} //getCMSFields_forPopup

} //dataobject

class RightContent_SideScreenImage extends Image {

function generateWebsiteThumnail($gd) {


//if nostyle is chosen i want it to be 218
return $gd->ResizeByWidth(218);

//return $gd->ResizeByWidth(194);




SS file
<% control RightContents %>

<% control SideScreenImage %>
<% end_control %>

<% end_control %>


Community Member, 99 Posts

20 July 2010 at 12:20am

I managed to do it in the ss file.

<% if CSSBoxStyle == "nostyle" %>

<% control SideScreenImage %>
<% end_control %>

<% else %>

<% control SideScreenImage %>
<% end_control %>

<% end_if %>

I couldn't seem to do it in the php as it was suggesting CSSBoxStyle was an unknown variable
whats the difference between doing in in the ss file or the php file?
is it related to performance?