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 /

Setting Width of Sidebar Column and Image in CMS


Reply


2 Posts   1025 Views

Avatar
Samba Sam

Community Member, 85 Posts

8 September 2009 at 12:32pm

Edited: 08/09/2009 12:33pm

Hi,
I am adding the option of specifying the left column and image width in the CMS in the Left Sidebar tab.
The user enters the width in the sidebar tab (e.g., 200px). I need to take that value, trim the px off, and
then minus the image border width, which is 4px total, 2px on the left 2px on the right so that the width of image equals the width of column.

I've tried variations of the following with no luck:

class Page_Controller extends ContentController {
}

class Page_Photo extends Image {

function generateLeftPhotoWidth($gd) {
$gd->setQuality(100);
return $gd->resizeByWidth(substr_replace($this->LeftWidth ,"",-2)-4);
}
}

In the above code, I tried to remove last two characters "px" of $LeftWidth and then subtract 4.

And in Page.ss, I have:
<img src="$LeftPhoto.LeftPhotoWidth.URL" title="$TitleText" alt="$AltText" />

Any ideas anyone?

Thanks,
Sam

Avatar
Samba Sam

Community Member, 85 Posts

12 September 2009 at 7:13am

Edited: 12/09/2009 7:14am

So, it appears the issue is that the function within the Page_Photo extends image class can't call up the $this leftwidth value. If I place a similar function (i.e. test()) in the ContentController, I get the correct output.
Actual code:
class Page_Photo extends Image {
function generateLeftPhotoWidth($gd) {
$width = substr_replace($this->LeftWidth ,"",-2)-4;
$gd->setQuality(100);
return $gd->resizeByWidth($width);
}

If I replace $this->LeftWidth with a specified px value the function works (e.g., "200px"), so I know the issue is $this.

Working test code:
class Page_Controller extends ContentController {
Function test() {
$width = substr_replace($this->LeftWidth ,"",-2)-4;
return $width;
}
}

Any ideas of how I can get the function generateLeftPhotoWidth in the Page_Photo class to work?
Thanks,
Sam