Jump to:

3393 Posts in 976 Topics by 852 members

Template Questions

SilverStripe Forums » Template Questions » Setting Width of Sidebar Column and Image in CMS

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

Page: 1
Go to End
Author Topic: 973 Views
  • Samba Sam
    Avatar
    Community Member
    85 Posts

    Setting Width of Sidebar Column and Image in CMS Link to this post

    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

  • Samba Sam
    Avatar
    Community Member
    85 Posts

    Re: Setting Width of Sidebar Column and Image in CMS Link to this post

    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

    973 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.